rewrite bird

This commit is contained in:
ace 2021-10-27 00:33:38 +03:00
parent 0bdd5f6950
commit f0e516002f
No known key found for this signature in database
GPG Key ID: 2E47CC17BA7F8CF0
8 changed files with 26 additions and 106 deletions

View File

@ -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

View File

@ -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

View File

@ -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 }}

View File

@ -0,0 +1,2 @@
install_date: 'Tue 26 Oct 2021 04:12:10 PM '
version: ''

View File

@ -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

View File

@ -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

View File

@ -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 %}

View File

@ -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