Refactor network role
This commit is contained in:
parent
8a4679c6f2
commit
317bed2eb6
@ -8,12 +8,15 @@
|
||||
|
||||
- name: systemd-networkd
|
||||
include: systemd-networkd.yml
|
||||
when: network_manage_systemd_networkd
|
||||
|
||||
- name: ifupdown
|
||||
include: ifupdown.yml
|
||||
when: network_manage_ifupdown
|
||||
|
||||
- name: netplan.io
|
||||
include: netplan.yml
|
||||
when: network_manage_netplan
|
||||
|
||||
# resolv.conf
|
||||
|
||||
|
@ -19,5 +19,15 @@
|
||||
dest: "/etc/systemd/network/05-{{ item.name }}.network"
|
||||
notify: restart systemd-networkd
|
||||
with_items: "{{ network_interfaces }}"
|
||||
when: _network_systemd_networkd_enabled | bool
|
||||
when:
|
||||
- network_interfaces is defined
|
||||
- _network_systemd_networkd_enabled | bool
|
||||
|
||||
- name: configure systemd-networkd default interface
|
||||
template:
|
||||
src: systemd-network.j2
|
||||
dest: "/etc/systemd/network/05-{{ ansible_default_ipv4.interface }}.network"
|
||||
notify: restart systemd-networkd
|
||||
when:
|
||||
- network_interfaces is not defined
|
||||
- _network_systemd_networkd_enabled | bool
|
||||
|
@ -0,0 +1,47 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
{% if network_interfaces is defined %}
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
{% for iface in network_interfaces %}
|
||||
{% if iface.name is defined %}
|
||||
{{ iface.name }}:
|
||||
{% endif %}
|
||||
{% if iface.address is defined %}
|
||||
addresses:
|
||||
{% for addr in iface.address %}
|
||||
- {{ addr }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if iface.gateway4 is defined %}
|
||||
gateway4: {{ iface.gateway4 }}
|
||||
{% endif %}
|
||||
{% if iface.gateway6 is defined %}
|
||||
gateway6: {{ iface.gateway6 }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{# Default network configuration #}
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
{% if ansible_default_ipv4.interface is defined %}
|
||||
{{ ansible_default_ipv4.interface }}:
|
||||
{% if ansible_default_ipv4.address is defined or ansible_default_ipv6.address is defined %}
|
||||
addresses:
|
||||
{% if ansible_default_ipv4.address is defined %}
|
||||
- {{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + "/" + ansible_default_ipv4.netmask) | ipaddr('prefix') }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv6.address is defined %}
|
||||
- {{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv4.gateway is defined %}
|
||||
gateway4: {{ ansible_default_ipv4.gateway }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv6.gateway is defined %}
|
||||
gateway6: {{ ansible_default_ipv6.gateway }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
@ -1,20 +1,41 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
{% if item is defined %}
|
||||
{% if item.name is defined %}
|
||||
[Match]
|
||||
Name={{ item.name }}
|
||||
|
||||
{% endif %}
|
||||
{% if item.address is defined %}
|
||||
[Network]
|
||||
{% if item.address is string %}
|
||||
Address={{ item.address }}
|
||||
{% else %}
|
||||
{% for address in item.address %}
|
||||
Address={{ address }}
|
||||
{% for addr in item.address %}
|
||||
Address={{ addr }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if item.gateway is string %}
|
||||
Gateway={{ item.gateway }}
|
||||
{% else %}
|
||||
{% for gateway in item.gateway %}
|
||||
Gateway={{ gateway }}
|
||||
{% endfor %}
|
||||
{% if item.gateway4 is defined %}
|
||||
Gateway={{ item.gateway4 }}
|
||||
{% endif %}
|
||||
{% if item.gateway6 is defined %}
|
||||
Gateway={{ item.gateway6 }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{# Default network configuration #}
|
||||
{% if ansible_default_ipv4.interface is defined %}
|
||||
[Match]
|
||||
Name={{ ansible_default_ipv4.interface }}
|
||||
{% if ansible_default_ipv4.address is defined or ansible_default_ipv6.address is defined %}
|
||||
[Network]
|
||||
{% if ansible_default_ipv4.address is defined %}
|
||||
Address={{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + "/" + ansible_default_ipv4.netmask) | ipaddr('prefix') }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv6.address is defined %}
|
||||
Address={{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv4.gateway is defined %}
|
||||
Gateway={{ ansible_default_ipv4.gateway }}
|
||||
{% endif %}
|
||||
{% if ansible_default_ipv6.gateway is defined %}
|
||||
Gateway={{ ansible_default_ipv6.gateway }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -8,4 +8,8 @@ _network_systemd_networkd_enabled: yes
|
||||
_network_systemd_resolved_enabled: no
|
||||
_network_resolv_conf_enabled: yes
|
||||
|
||||
network_manage_ifupdown: no
|
||||
network_manage_systemd_networkd: yes
|
||||
network_manage_netplan: no
|
||||
|
||||
# vim:ft=yaml.ansible:
|
||||
|
Loading…
Reference in New Issue
Block a user