Refactor network role
This commit is contained in:
parent
8a4679c6f2
commit
317bed2eb6
@ -8,12 +8,15 @@
|
|||||||
|
|
||||||
- name: systemd-networkd
|
- name: systemd-networkd
|
||||||
include: systemd-networkd.yml
|
include: systemd-networkd.yml
|
||||||
|
when: network_manage_systemd_networkd
|
||||||
|
|
||||||
- name: ifupdown
|
- name: ifupdown
|
||||||
include: ifupdown.yml
|
include: ifupdown.yml
|
||||||
|
when: network_manage_ifupdown
|
||||||
|
|
||||||
- name: netplan.io
|
- name: netplan.io
|
||||||
include: netplan.yml
|
include: netplan.yml
|
||||||
|
when: network_manage_netplan
|
||||||
|
|
||||||
# resolv.conf
|
# resolv.conf
|
||||||
|
|
||||||
|
@ -19,5 +19,15 @@
|
|||||||
dest: "/etc/systemd/network/05-{{ item.name }}.network"
|
dest: "/etc/systemd/network/05-{{ item.name }}.network"
|
||||||
notify: restart systemd-networkd
|
notify: restart systemd-networkd
|
||||||
with_items: "{{ network_interfaces }}"
|
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 }}
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
{% if item is defined %}
|
||||||
|
{% if item.name is defined %}
|
||||||
[Match]
|
[Match]
|
||||||
Name={{ item.name }}
|
Name={{ item.name }}
|
||||||
|
{% endif %}
|
||||||
|
{% if item.address is defined %}
|
||||||
[Network]
|
[Network]
|
||||||
{% if item.address is string %}
|
{% for addr in item.address %}
|
||||||
Address={{ item.address }}
|
Address={{ addr }}
|
||||||
{% else %}
|
|
||||||
{% for address in item.address %}
|
|
||||||
Address={{ address }}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.gateway is string %}
|
{% if item.gateway4 is defined %}
|
||||||
Gateway={{ item.gateway }}
|
Gateway={{ item.gateway4 }}
|
||||||
{% else %}
|
{% endif %}
|
||||||
{% for gateway in item.gateway %}
|
{% if item.gateway6 is defined %}
|
||||||
Gateway={{ gateway }}
|
Gateway={{ item.gateway6 }}
|
||||||
{% endfor %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
@ -8,4 +8,8 @@ _network_systemd_networkd_enabled: yes
|
|||||||
_network_systemd_resolved_enabled: no
|
_network_systemd_resolved_enabled: no
|
||||||
_network_resolv_conf_enabled: yes
|
_network_resolv_conf_enabled: yes
|
||||||
|
|
||||||
|
network_manage_ifupdown: no
|
||||||
|
network_manage_systemd_networkd: yes
|
||||||
|
network_manage_netplan: no
|
||||||
|
|
||||||
# vim:ft=yaml.ansible:
|
# vim:ft=yaml.ansible:
|
||||||
|
Loading…
Reference in New Issue
Block a user