diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..2e45245 --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,4 @@ +# use 'nm' for network-manager and dummy0 iface for BGP IPs +# use 'network-scripts' for network-scripts and lo iface for BGP IPs +network: "nm" +network_nm_iface: "dummy0" diff --git a/handlers/main.yml b/handlers/main.yml index f9f7235..ad0cd66 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -16,4 +16,4 @@ ifdown lo ; ifup lo - name: Reload dummy interface - command: nmcli conn up {{ dummy_iface | default('dummy0') }} + command: nmcli conn up {{ network_nm_iface }} diff --git a/tasks/RedHat/8.yaml b/tasks/RedHat/8.yaml index e1b1321..e187143 100644 --- a/tasks/RedHat/8.yaml +++ b/tasks/RedHat/8.yaml @@ -1,39 +1,41 @@ --- -- name: Install network scripts - package: - name: network-scripts - state: present - - name: Install BIRD package: name: bird state: present -- name: Update ifcfg-lo config - template: - src: ifcfg-lo.j2 - dest: /etc/sysconfig/network-scripts/ifcfg-lo - notify: - - Restart loopback +- block: + - name: Install network scripts + package: + name: network-scripts + state: present + + - name: Update ifcfg-lo config + template: + src: ifcfg-lo.j2 + dest: /etc/sysconfig/network-scripts/ifcfg-lo + notify: + - Restart loopback + when: network == 'network-scripts' -#- name: Add dummy interface and add IPs -# community.general.nmcli: -# type: dummy -# conn_name: "{{ dummy_iface | default('dummy0') }}" -# ip4: '{{ item.ip4 }}' -# state: present -# notify: -# - Reload dummy interface -# loop: | -# [ -# {% for protocol_static in bird.bgp.static %} -# {% for network in protocol_static['networks'][ansible_fqdn] %} -# { -# "ip4": "{{ network['ip'] + '/' + network['mask_dash'] }}" -# }, -# {% endfor %} -# {% endfor %} -# ] +- name: Add dummy interface and add IPs + community.general.nmcli: + type: dummy + conn_name: "{{ network_nm_iface }}" + ip4: | + [ + {% set ips = [] %} + {% for protocol_static in bird.bgp.static %} + {% for network in protocol_static['networks'][ansible_fqdn] %} + {{ ips.append(network['ip'] + '/' + network['mask_dash']) }} + {% endfor %} + {% endfor %} + "{{ ips | join(',') }}" + ] + state: present + notify: + - Reload dummy interface + when: network == 'nm' - name: Add BIRD config template: