From f0e516002fcfed54f68492c38fa2ad67adbd8cf5 Mon Sep 17 00:00:00 2001 From: ace Date: Wed, 27 Oct 2021 00:33:38 +0300 Subject: [PATCH] rewrite bird --- README.md | 54 ++++++++++++++------------------------- defaults/main.yaml | 7 ----- handlers/main.yml | 4 +-- meta/.galaxy_install_info | 2 ++ tasks/RedHat/7.yaml | 10 ++------ tasks/RedHat/8.yaml | 38 --------------------------- templates/bird.conf.j2 | 2 +- templates/ifcfg-lo.j2 | 15 ----------- 8 files changed, 26 insertions(+), 106 deletions(-) create mode 100644 meta/.galaxy_install_info delete mode 100644 templates/ifcfg-lo.j2 diff --git a/README.md b/README.md index 5f2afb4..b4f0ac2 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,9 @@ -Setup BIRD with BGP on loopback or dummy interface - -For RHEL8 use 'nm' for NetworkManager and dummy iface for BGP IPs -For RHEL7 use 'ns' for network-scripts and lo iface for BGP IPs - - network: "nm" - network_nm_iface: "dummy0" - -Use 0 for MTU auto - - network_nm_iface_mtu: 0 +Setup BIRD with BGP +Use with network role for loopback/dummy interface configuraton BIRD config example: + bird_interface: "dummy0" bird: bgp: common: @@ -27,41 +19,33 @@ BIRD config example: - name: STATIC1 networks: storage04.s3.msk2.example.com: - - ip: "10.110.42.1" - mask: "255.255.255.255" - mask_dash: "32" + - ip: "10.110.42.1/32" bgp_local_pref: "100" - - ip: "10.110.42.21" - mask: "255.255.255.255" - mask_dash: "32" + interface: "{{ bird_interface }}" + - ip: "10.110.42.21/32" bgp_local_pref: "100" + interface: "{{ bird_interface }}" storage05.s3.msk2.example.com: - - ip: "10.110.42.1" - mask: "255.255.255.255" - mask_dash: "32" + - ip: "10.110.42.1/32" bgp_local_pref: "100" - - ip: "10.110.42.21" - mask: "255.255.255.255" - mask_dash: "32" + interface: "{{ bird_interface }}" + - ip: "10.110.42.21/32" bgp_local_pref: "100" + interface: "{{ bird_interface }}" storage06.s3.msk2.example.com: - - ip: "10.110.42.1" - mask: "255.255.255.255" - mask_dash: "32" + - ip: "10.110.42.1/32" bgp_local_pref: "100" - - ip: "10.110.42.21" - mask: "255.255.255.255" - mask_dash: "32" + interface: "{{ bird_interface }}" + - ip: "10.110.42.21/32" bgp_local_pref: "100" + interface: "{{ bird_interface }}" storage07.s3.msk2.example.com: - - ip: "10.110.42.1" - mask: "255.255.255.255" - mask_dash: "32" + - ip: "10.110.42.1/32" bgp_local_pref: "100" - - ip: "10.110.42.21" - mask: "255.255.255.255" - mask_dash: "32" + interface: "{{ bird_interface }}" + - ip: "10.110.42.21/32" bgp_local_pref: "100" + interface: "{{ bird_interface }}" bgp: - name: SW06 remote_asnum: 4200200000 diff --git a/defaults/main.yaml b/defaults/main.yaml index 40785cf..e69de29 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,7 +0,0 @@ -# use 'nm' for NetworkManager and dummy iface for BGP IPs -# use 'ns' for network-scripts and lo iface for BGP IPs -network: "nm" -network_nm_iface: "dummy0" - -# 0 for MTU auto -network_nm_iface_mtu: 0 diff --git a/handlers/main.yml b/handlers/main.yml index ad0cd66..7c4de7a 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -15,5 +15,5 @@ shell: | ifdown lo ; ifup lo -- name: Reload dummy interface - command: nmcli conn up {{ network_nm_iface }} +- name: Reload dummy interface with nmcli + command: nmcli conn up {{ bird_network_nm_iface }} diff --git a/meta/.galaxy_install_info b/meta/.galaxy_install_info new file mode 100644 index 0000000..559ceef --- /dev/null +++ b/meta/.galaxy_install_info @@ -0,0 +1,2 @@ +install_date: 'Tue 26 Oct 2021 04:12:10 PM ' +version: '' diff --git a/tasks/RedHat/7.yaml b/tasks/RedHat/7.yaml index a559ed2..aa9a875 100644 --- a/tasks/RedHat/7.yaml +++ b/tasks/RedHat/7.yaml @@ -4,19 +4,12 @@ name: bird2 state: present -- name: Update ifcfg-lo config - template: - src: ifcfg-lo.j2 - dest: /etc/sysconfig/network-scripts/ifcfg-lo - notify: - - Restart loopback - - name: Add BIRD config template: src: bird.conf.j2 dest: /etc/bird.conf notify: - - Reload bird + - Reload BIRD - name: Start BIRD service systemd: @@ -24,3 +17,4 @@ state: started enabled: yes daemon_reload: yes + diff --git a/tasks/RedHat/8.yaml b/tasks/RedHat/8.yaml index 47d6f63..de71e6a 100644 --- a/tasks/RedHat/8.yaml +++ b/tasks/RedHat/8.yaml @@ -4,44 +4,6 @@ name: bird state: present -- 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 == 'ns' - - -- block: - - name: BGP IPs string for nmcli - set_fact: - ips: |- - {%- set ips_list = [] %} - {%- for protocol_static in bird.bgp.static %} - {%- for network in protocol_static['networks'][ansible_fqdn] %} - {{ ips_list.append(network['ip'] + '/' + network['mask_dash']) }} - {%- endfor %} - {%- endfor %} - {{ ips_list | join(', ') }} - - - name: Add dummy interface and add IPs - community.general.nmcli: - type: dummy - conn_name: "{{ network_nm_iface }}" - ip4: "{{ ips }}" - mtu: "{{ network_nm_iface_mtu }}" - state: present - notify: - - Reload dummy interface - when: network == 'nm' - - name: Add BIRD config template: src: bird.conf.j2 diff --git a/templates/bird.conf.j2 b/templates/bird.conf.j2 index f2c88a4..1e18da2 100644 --- a/templates/bird.conf.j2 +++ b/templates/bird.conf.j2 @@ -24,7 +24,7 @@ protocol kernel KERNEL6 { protocol static {{ protocol_static.name }} { ipv4; {% for network in protocol_static['networks'][inventory_hostname] %} - route {{ network.ip }}/{{ network.mask_dash }} via "lo" { bgp_local_pref = {{ network.bgp_local_pref }}; }; + route {{ network.ip }} via "{{ network.interface }}" { bgp_local_pref = {{ network.bgp_local_pref }}; }; {% endfor %} } {% endfor %} diff --git a/templates/ifcfg-lo.j2 b/templates/ifcfg-lo.j2 deleted file mode 100644 index a748591..0000000 --- a/templates/ifcfg-lo.j2 +++ /dev/null @@ -1,15 +0,0 @@ -DEVICE=lo -IPADDR=127.0.0.1 -NETMASK=255.0.0.0 -NETWORK=127.0.0.0 -# If you're having problems with gated making 127.0.0.0/8 a martian, -# you can change this to something else (255.255.255.255, for example) -BROADCAST=127.255.255.255 -{% for protocol_static in bird.bgp.static %} -{% for network in protocol_static['networks'][ansible_fqdn] %} -IPADDR{{ loop.index }}={{ network['ip'] }} -NETMASK{{ loop.index }}={{ network['mask'] }} -{% endfor %} -{% endfor %} -ONBOOT=yes -NAME=loopback