Network role fixes

This commit is contained in:
Ryan Cavicchioni 2019-08-25 02:07:11 +00:00
parent b44f626df6
commit de19dd6104
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
5 changed files with 72 additions and 60 deletions

View File

@ -1,6 +1,6 @@
--- ---
network_interfaces: network_interfaces:
- name: "{{ facter_networking.primary }}" - name: "{{ ansible_default_ipv4.interface }}"
address: address:
- "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.address + '/' + ansible_default_ipv4.netmask) | ipaddr('prefix') }}" - "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.address + '/' + ansible_default_ipv4.netmask) | ipaddr('prefix') }}"
- "{{ ansible_default_ipv6.address + '/' + ansible_default_ipv6.prefix }}" - "{{ ansible_default_ipv6.address + '/' + ansible_default_ipv6.prefix }}"

View File

@ -0,0 +1,22 @@
---
# 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

View File

@ -1,67 +1,19 @@
--- ---
- name: gather OS specific variables - name: gather OS specific variables
include_vars: "{{ item }} " include_vars: "{{ item }}"
with_first_found: with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml" - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
- "{{ ansible_distribution }}.yaml" - "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml" - "{{ ansible_os_family }}.yaml"
# systemd-networkd - name: systemd-networkd
include: systemd-networkd.yml
- name: manage systemd-networkd package - name: ifupdown
package: include: ifupdown.yml
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 - name: netplan.io
service: include: netplan.yml
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_systemd_networkd_enabled
# 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
# netplan.io
- 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
notify: netplan apply
when: _network_netplan_enabled
# resolv.conf # resolv.conf
@ -70,7 +22,7 @@
src: resolv.conf.j2 src: resolv.conf.j2
dest: /etc/resolv.conf dest: /etc/resolv.conf
notify: restart systemd-resolved notify: restart systemd-resolved
when: _network_resolv_conf_enabled when: _network_resolv_conf_enabled | bool
# systemd-resolved # systemd-resolved
@ -86,19 +38,19 @@
dest: /etc/resolv.conf dest: /etc/resolv.conf
state: link state: link
force: yes force: yes
when: _network_systemd_resolved_enabled when: _network_systemd_resolved_enabled | bool
- name: configure systemd-resolved - name: configure systemd-resolved
template: template:
src: resolved.conf.j2 src: resolved.conf.j2
dest: /etc/systemd/resolved.conf dest: /etc/systemd/resolved.conf
notify: restart systemd-resolved notify: restart systemd-resolved
when: _network_systemd_resolved_enabled when: _network_systemd_resolved_enabled | bool
- name: remove systemd-resolved configuration - name: remove systemd-resolved configuration
file: file:
path: /etc/systemd/resolved.conf path: /etc/systemd/resolved.conf
state: absent state: absent
when: not _network_systemd_resolved_enabled when: not _network_systemd_resolved_enabled | bool
# vim:ft=yaml.ansible: # vim:ft=yaml.ansible:

View File

@ -0,0 +1,15 @@
---
# netplan.io
- 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
notify: netplan apply
when: _network_netplan_enabled | bool

View File

@ -0,0 +1,23 @@
---
# 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_systemd_networkd_enabled | bool