Simply network role
The role only supports netplan now
This commit is contained in:
parent
221578a0d1
commit
71d1da1cf1
@ -1,15 +1 @@
|
|||||||
---
|
---
|
||||||
network_nameservers: []
|
|
||||||
network_resolv_conf_options:
|
|
||||||
- edns0
|
|
||||||
|
|
||||||
_network_resolv_conf_enabled: yes
|
|
||||||
|
|
||||||
_network_systemd_networkd_service_name: systemd-networkd.service
|
|
||||||
_network_ifupdown_service_name: networking.service
|
|
||||||
_network_systemd_resolved_service_name: systemd-resolved.service
|
|
||||||
|
|
||||||
_network_ifupdown_package_name: ifupdown
|
|
||||||
_network_netplan_package_name: netplan.io
|
|
||||||
|
|
||||||
# vim:ft=yaml.ansible:
|
|
||||||
|
@ -1,24 +1,3 @@
|
|||||||
---
|
---
|
||||||
- name: restart systemd-networkd
|
|
||||||
service:
|
|
||||||
name: "{{ _network_systemd_networkd_service_name }}"
|
|
||||||
state: restarted
|
|
||||||
when: _network_systemd_networkd_enabled
|
|
||||||
|
|
||||||
- name: restart ifupdown
|
|
||||||
service:
|
|
||||||
name: "{{ _network_ifupdown_service_name }}"
|
|
||||||
state: restarted
|
|
||||||
when: _network_ifupdown_enabled
|
|
||||||
|
|
||||||
- name: netplan apply
|
- name: netplan apply
|
||||||
command: netplan apply
|
command: netplan apply
|
||||||
when: _network_netplan_enabled
|
|
||||||
|
|
||||||
- name: restart systemd-resolved
|
|
||||||
service:
|
|
||||||
name: "{{ _network_systemd_resolved_service_name }}"
|
|
||||||
state: restarted
|
|
||||||
when: _network_systemd_resolved_available
|
|
||||||
|
|
||||||
# vim:ft=yaml.ansible:
|
|
||||||
|
6
roles/network/tasks/Ubuntu.yaml
Normal file
6
roles/network/tasks/Ubuntu.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Include netplan vars
|
||||||
|
include_vars: netplan.yaml
|
||||||
|
|
||||||
|
- name: Include netplan tasks
|
||||||
|
include_tasks: netplan.yml
|
@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
# ifupdown
|
|
||||||
|
|
||||||
- name: manage ifupdown services
|
|
||||||
service:
|
|
||||||
name: "{{ _network_ifupdown_service_name }}"
|
|
||||||
state: "{{ _network_ifupdown_enabled | ternary('started', 'stopped') }}"
|
|
||||||
enabled: "{{ _network_ifupdown_enabled }}"
|
|
||||||
|
|
||||||
- name: manage ifupdown package
|
|
||||||
package:
|
|
||||||
name: "{{ _network_ifupdown_package_name }}"
|
|
||||||
state: "{{ _network_ifupdown_enabled | ternary('present', 'absent') }}"
|
|
||||||
|
|
||||||
- name: manage /etc/network/interfaces
|
|
||||||
template:
|
|
||||||
src: network-interfaces.j2
|
|
||||||
dest: /etc/network/interfaces
|
|
||||||
notify: restart ifupdown
|
|
||||||
with_items: "{{ network_interfaces }}"
|
|
||||||
when: _network_ifupdown_enabled | bool
|
|
||||||
|
|
@ -22,55 +22,3 @@
|
|||||||
- "default.yaml"
|
- "default.yaml"
|
||||||
paths:
|
paths:
|
||||||
- tasks
|
- tasks
|
||||||
|
|
||||||
- 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
|
|
||||||
|
|
||||||
- name: configure resolv.conf
|
|
||||||
template:
|
|
||||||
src: resolv.conf.j2
|
|
||||||
dest: /etc/resolv.conf
|
|
||||||
notify: restart systemd-resolved
|
|
||||||
when: _network_resolv_conf_enabled | bool
|
|
||||||
|
|
||||||
# systemd-resolved
|
|
||||||
|
|
||||||
- name: manage systemd-resolved service
|
|
||||||
service:
|
|
||||||
name: "{{ _network_systemd_resolved_service_name }}"
|
|
||||||
state: "{{ _network_systemd_resolved_enabled | ternary('started', 'stopped') }}"
|
|
||||||
enabled: "{{ _network_systemd_resolved_enabled }}"
|
|
||||||
|
|
||||||
- name: symlink /etc/resolv.conf
|
|
||||||
file:
|
|
||||||
src: /run/systemd/resolve/stub-resolv.conf
|
|
||||||
dest: /etc/resolv.conf
|
|
||||||
state: link
|
|
||||||
force: yes
|
|
||||||
when: _network_systemd_resolved_enabled | bool
|
|
||||||
|
|
||||||
- name: configure systemd-resolved
|
|
||||||
template:
|
|
||||||
src: resolved.conf.j2
|
|
||||||
dest: /etc/systemd/resolved.conf
|
|
||||||
notify: restart systemd-resolved
|
|
||||||
when: _network_systemd_resolved_enabled | bool
|
|
||||||
|
|
||||||
- name: remove systemd-resolved configuration
|
|
||||||
file:
|
|
||||||
path: /etc/systemd/resolved.conf
|
|
||||||
state: absent
|
|
||||||
when: not _network_systemd_resolved_enabled | bool
|
|
||||||
|
|
||||||
# vim:ft=yaml.ansible:
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
---
|
---
|
||||||
# netplan.io
|
- name: Configure netplan
|
||||||
|
copy:
|
||||||
- name: manage netplan package
|
|
||||||
package:
|
|
||||||
name: "{{ _network_netplan_package_name }}"
|
|
||||||
state: "{{ _network_netplan_enabled | ternary('present', 'absent') }}"
|
|
||||||
|
|
||||||
- name: manage netplan
|
|
||||||
template:
|
|
||||||
src: netcfg.yaml.j2
|
|
||||||
dest: /etc/netplan/01-netcfg.yaml
|
dest: /etc/netplan/01-netcfg.yaml
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
content: "{{ network_netplan_config | to_nice_yaml }}"
|
||||||
notify: netplan apply
|
notify: netplan apply
|
||||||
when: _network_netplan_enabled | bool
|
|
||||||
|
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
# systemd-networkd
|
|
||||||
|
|
||||||
- name: manage systemd-networkd package
|
|
||||||
package:
|
|
||||||
name: "{{ _network_systemd_networkd_package_name }}"
|
|
||||||
state: "{{ _network_systemd_networkd_enabled | ternary('present', 'absent') }}"
|
|
||||||
when: _systemd_networkd_package_name is defined
|
|
||||||
|
|
||||||
- name: manage systemd-networkd service
|
|
||||||
service:
|
|
||||||
name: "{{ _network_systemd_networkd_service_name }}"
|
|
||||||
state: "{{ _network_systemd_networkd_enabled | ternary('started', 'stopped') }}"
|
|
||||||
enabled: "{{ _network_systemd_networkd_enabled }}"
|
|
||||||
|
|
||||||
- name: configure systemd-networkd
|
|
||||||
template:
|
|
||||||
src: systemd-network.j2
|
|
||||||
dest: "/etc/systemd/network/05-{{ item.name }}.network"
|
|
||||||
notify: restart systemd-networkd
|
|
||||||
with_items: "{{ network_interfaces }}"
|
|
||||||
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
|
|
@ -1,47 +0,0 @@
|
|||||||
# {{ 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) | ansible.utils.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,8 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
{% if _network_ifupdown_enabled %}
|
|
||||||
{% elif _network_netplan_enabled %}
|
|
||||||
# netplan is in use.
|
|
||||||
{% elif _network_systemd_networkd_enabled %}
|
|
||||||
# systemd-networkd is in use.
|
|
||||||
{% endif %}
|
|
@ -1,15 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
{% for ns in (network_nameservers | shuffle(seed=inventory_hostname))[:3] %}
|
|
||||||
nameserver {{ ns }}
|
|
||||||
{% endfor %}
|
|
||||||
{% if network_resolv_conf_options is defined %}
|
|
||||||
options {{ network_resolv_conf_options | join(' ') }}
|
|
||||||
{% endif %}
|
|
||||||
{% if network_search is defined %}
|
|
||||||
{% if network_search is iterable and network_search is not string %}
|
|
||||||
search {{ network_search | join(' ') }}
|
|
||||||
{% else %}
|
|
||||||
search {{ network_search }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
@ -1,13 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
[Resolve]
|
|
||||||
{% for ns in (network_nameservers | shuffle(seed=inventory_hostname)) %}
|
|
||||||
DNS={{ ns }}
|
|
||||||
{% endfor %}
|
|
||||||
{% if network_search is defined %}
|
|
||||||
{% if network_search is iterable and network_search is not string %}
|
|
||||||
Domains={{ network_search | join(' ') }}
|
|
||||||
{% else %}
|
|
||||||
Domains={{ network_search }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
@ -1,41 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
{% if item is defined %}
|
|
||||||
{% if item.name is defined %}
|
|
||||||
[Match]
|
|
||||||
Name={{ item.name }}
|
|
||||||
{% endif %}
|
|
||||||
{% if item.address is defined %}
|
|
||||||
[Network]
|
|
||||||
{% for addr in item.address %}
|
|
||||||
Address={{ addr }}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% 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) | ansible.utils.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 %}
|
|
@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
# vars file for roles/network
|
|
15
roles/network/vars/netplan.yaml
Normal file
15
roles/network/vars/netplan.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
network_netplan_config:
|
||||||
|
network:
|
||||||
|
version: 2
|
||||||
|
renderer: networkd
|
||||||
|
ethernets:
|
||||||
|
eth0:
|
||||||
|
dhcp4: 'no'
|
||||||
|
dhcp6: 'no'
|
||||||
|
addresses:
|
||||||
|
- "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask) | ansible.utils.ipaddr('prefix') }}"
|
||||||
|
- "{{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}"
|
||||||
|
gateway4: "{{ ansible_default_ipv4.gateway }}"
|
||||||
|
gateway6: "{{ ansible_default_ipv6.gateway }}"
|
||||||
|
nameservers:
|
||||||
|
addresses: "{{ dns_servers }}"
|
Loading…
Reference in New Issue
Block a user