hostname {{ inventory_hostname.replace("_","-") }}
!
logging monitor debugging
!
lldp run
{% if af.ipv4|default(False) %}
ip routing
{% endif %}
{% if af.ipv6|default(False) %}
ipv6 unicast-routing
{% endif %}
!
{% if vrfs is defined %}
{% include 'eos.vrf.j2' %}
{% endif %}
!
{% for k,v in hostvars.items() if k != inventory_hostname and v.af.ipv4|default(False) %}
ip host {{ k|replace('_','') }}{% if v.loopback.ipv4 is defined %} {{ v.loopback.ipv4|ipaddr('address') }}{% endif %}
{%- for l in v.interfaces|default([]) if 'ipv4' in l and l.ipv4 != True and l.ipv4|ipv4 %} {{ l.ipv4|ipaddr('address') }}{% endfor %}

{% endfor %}
{% for k,v in hostvars.items() if k != inventory_hostname and v.loopback.ipv6 is defined %}
ipv6 host {{ k }} {{ v.loopback.ipv6|ipaddr('address') }}
{% endfor %}
{% if mtu is defined %}
!
interface defaults
 mtu {{ mtu }}
{% endif %}
!
interface Loopback0
{% if 'ipv4' in loopback %}
 ip address {{ loopback.ipv4 }}
{% endif %}
{% if 'ipv6' in loopback %}
 ipv6 address {{ loopback.ipv6 }}
{% endif %}
!
interface {{ mgmt.ifname|default('Management1') }}
 no lldp transmit
 no lldp receive
!
{% for l in interfaces|default([]) %}
interface {{ l.ifname }}
 no shutdown
{% if l.virtual_interface is not defined %}
 no switchport
{% endif %}
{% if l.vrf is defined %}
 vrf {{ l.vrf }}
{% endif %}
{% if l.mtu is defined %}
 mtu {{ l.mtu }}
{% endif %}
{% if l.name is defined %}
 description {{ l.name }}{{ " ["+l.role+"]" if l.role is defined else "" }}
{% elif l.type|default("") == "stub" %}
 description Stub interface
{% endif %}
{#
    Set interface IPv4 addresses
#}
{% if 'ipv4' in l %}
{%   if l.ipv4 == True %}
 ip address unnumbered {{ loopback_name|default('Loopback 0') }}
{%   elif l.ipv4|ipv4 %}
 ip address {{ l.ipv4 }}
{%   else %}
! Invalid IPv4 address {{ l.ipv4 }}
{%   endif %}
{% endif %}
{#
    Set interface IPv6 addresses
#}
{% if 'ipv6' in l %}
{%   if l.ipv6 == True %}
 ipv6 enable
{%   elif l.ipv6|ipv6 %}
 ipv6 address {{ l.ipv6 }}
{%   else %}
! Invalid IPv6 address {{ l.ipv6 }}
{%   endif %}
{% endif %}
{% if l.virtual_interface is not defined %}
!
 mac-address {{ '52dc.cafe.%02d%02d' % ( id,l.ifindex ) }}
{% endif %}
!
{% endfor %}
