ansible-role-network/templates/interfaces.j2

25 lines
699 B
Text
Raw Normal View History

2021-08-24 17:40:28 +00:00
# {{ ansible_managed }}
auto lo
iface lo inet loopback
{% for interface_name, interface in network_interfaces.items() %}
auto {{ interface_name }}
{% if interface.dhcp is defined and interface.dhcp %}
iface {{ interface_name }} inet dhcp
{% else %}
iface {{ interface_name }} inet static
address {{ interface.address }}
netmask {{ interface.netmask }}
{% if interface.gateway is defined %}
gateway {{ interface.gateway }}
{% endif %}
{% endif %}
{% if interface.routes is defined %}
{% for route in interface.routes %}
post-up ip route add {{ route.subnet }} via {{ route.gateway }}
post-down ip route del {{ route.subnet }} via {{ route.gateway }}
{% endfor %}
{% endif %}
{% endfor %}