diff --git a/ansible/templates/minigraph_link_meta.j2 b/ansible/templates/minigraph_link_meta.j2
index 2180faa461..695d7cc7cf 100644
--- a/ansible/templates/minigraph_link_meta.j2
+++ b/ansible/templates/minigraph_link_meta.j2
@@ -1,6 +1,25 @@
-{% if 'dualtor' in topo %}
+{% set link_metadata_defined = False %}
+
+{% if 'dualtor' in topo or
+ (macsec_card is defined and macsec_card == True and 't2' in topo) %}
+ {% set link_metadata_defined = True %}
+{% endif %}
+
+{% if device_conn is defined and inventory_hostname in device_conn %}
+ {% for iface in device_conn[inventory_hostname] %}
+ {% if 'autoneg' in device_conn[inventory_hostname][iface] and
+ 'on' in device_conn[inventory_hostname][iface]['autoneg'] %}
+ {% set link_metadata_defined = True %}
+ {% endif %}
+ {% endfor %}
+{% endif %}
+
+{% if link_metadata_defined %}
+{% endif %}
+
+{% if 'dualtor' in topo %}
{% for tunnel in tunnel_configs %}
@@ -24,13 +43,9 @@
{{ dual_tor_facts['positions']['lower'] }}:{{ tunnel }};{{ dual_tor_facts['positions']['upper'] }}:{{ tunnel }}
{% endfor %}
-
-
{% endif %}
{% if macsec_card is defined and macsec_card == True and 't2' in topo %}
-
-
{% for index in range(vms_number) %}
{% set vm_intfs=vm_topo_config['vm'][vms[index]]['intfs'][dut_index|int]|sort %}
{% set dut_intfs=vm_topo_config['vm'][vms[index]]['interface_indexes'][dut_index|int]|sort %}
@@ -49,38 +64,35 @@
{% endif %}
{% endfor %}
{% endfor %}
-
-
{% endif %}
-{% if msft_an_enabled is defined and vm_topo_config.get('autoneg_interfaces') is not none %}
-
-
-{% for if_index in vm_topo_config['autoneg_interfaces']['intfs'] %}
-
-{% if "mellanox" in device_info[inventory_hostname]['HwSku']|lower %}
-{% set autoneg_intf = "etp" ~ if_index %}
-{% else %}
-{% set autoneg_intf = "Ethernet" ~ if_index ~ "/1" %}
-{% endif %}
-{% if port_alias_map[autoneg_intf] in device_conn[inventory_hostname] and device_conn[inventory_hostname][port_alias_map[autoneg_intf]]['autoneg']|lower == "on" %}
+{% if device_conn is defined and inventory_hostname in device_conn %}
+{% for iface_name in device_conn[inventory_hostname].keys() %}
+ {% if iface_name in device_conn[inventory_hostname] and 'autoneg' in device_conn[inventory_hostname][iface_name] %}
+ {% if 'on' in device_conn[inventory_hostname][iface_name]['autoneg'] %}
-
- AutoNegotiation
- True
-
-
- FECDisabled
-
- True
-
+
+ AutoNegotiation
+ True
+
+ {% if msft_an_enabled is defined %}
+
+ FECDisabled
+
+ True
+
+ {% endif %}
- {{ device_conn[inventory_hostname][port_alias_map[autoneg_intf]]['peerdevice'] }}:{{ device_conn[inventory_hostname][port_alias_map[autoneg_intf]]['peerport'] }};{{ inventory_hostname }}:{{ autoneg_intf }}
-
-{% endif %}
+ {{ device_conn[inventory_hostname][iface_name]['peerdevice'] }}:{{ device_conn[inventory_hostname][iface_name]['peerport'] }};{{ inventory_hostname }}:{{ port_name_map[iface_name] }}
+
+ {% endif %}
+ {% endif %}
{% endfor %}
+{% endif %}
+
+{% if link_metadata_defined %}
{% endif %}