diff --git a/ansible/router/main/base.yaml b/ansible/router/main/base.yaml index e9d5502b57e80ddb22d77b6d1069f051b7cc0660..8f896bec1fe01e07e068fecbdb926f79297950ff 100644 --- a/ansible/router/main/base.yaml +++ b/ansible/router/main/base.yaml @@ -1,6 +1,7 @@ --- - hosts: all + become: yes roles: - role: kszk.base tags: ["base"] @@ -8,4 +9,7 @@ tags: ["iptables"] vars_files: - "vars/base.yaml" - tasks: [] + tasks: + - name: Setup bgp + tags: ["bgp"] + import_tasks: tasks/bgp.yaml diff --git a/ansible/router/main/tasks/bgp.yaml b/ansible/router/main/tasks/bgp.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fa52613db05aa7efc60c0e51ab8c1b47cd3d2298 --- /dev/null +++ b/ansible/router/main/tasks/bgp.yaml @@ -0,0 +1,59 @@ +--- + +- name: Install required packages for bgp + package: + state: present + name: + - frr + - gobgpd + +- name: Create opt/gobgpd folder + file: + path: /opt/gobgpd + state: directory + +- name: Download gobgpd tar file and extract it + unarchive: + src: https://github.com/osrg/gobgp/releases/download/v2.33.0/gobgp_2.33.0_linux_amd64.tar.gz + dest: /opt/gobgpd + remote_src: yes + +- name: Place frr config file + template: + src: etc/frr/daemons.j2 + dest: /etc/frr/daemons + mode: 0640 + register: frr_config_file + +- name: Ensure frr is restarted and enabled to start at boot + service: + name: frr + state: restarted + enabled: yes + when: frr_config_file.changed + +- name: Place gobgpd systemd service file + template: + src: etc/systemd/system/gobgpd.service.j2 + dest: /etc/systemd/system/gobgpd.service + mode: 0644 + register: gobgpd_service_config_file + +- name: Place gobgpd config file + template: + src: etc/gobgpd.conf.j2 + dest: /etc/gobgpd.conf + mode: 0644 + register: gobgpd_config_file + +- name: Force systemd to reread configs + ansible.builtin.systemd: + daemon_reload: yes + when: gobgpd_service_config_file.changed + +- name: Ensure gobgpd is restarted and enabled to start at boot + service: + name: gobgpd + state: restarted + enabled: yes + when: gobgpd_config_file.changed or gobgpd_service_config_file.changed diff --git a/ansible/router/main/templates/etc/frr/daemons.j2 b/ansible/router/main/templates/etc/frr/daemons.j2 new file mode 100644 index 0000000000000000000000000000000000000000..04ecfbf64d815a729023e7e14f57e0d8a5d76c95 --- /dev/null +++ b/ansible/router/main/templates/etc/frr/daemons.j2 @@ -0,0 +1,47 @@ +# +# !!! +# {{ ansible_managed }} +# !!! + +bgpd=no +ospfd=no +ospf6d=no +ripd=no +ripngd=no +isisd=no +pimd=no +ldpd=no +nhrpd=no +eigrpd=no +babeld=no +sharpd=no +pbrd=no +bfdd=no +fabricd=no +vrrpd=no +zebra=yes + +# +# If this option is set the /etc/init.d/frr script automatically loads +# the config via "vtysh -b" when the servers are started. +# Check /etc/pam.d/frr if you intend to use "vtysh"! +# +vtysh_enable=yes +zebra_options=" -A 127.0.0.1 -s 90000000" +bgpd_options=" -A 127.0.0.1" +ospfd_options=" -A 127.0.0.1" +ospf6d_options=" -A ::1" +ripd_options=" -A 127.0.0.1" +ripngd_options=" -A ::1" +isisd_options=" -A 127.0.0.1" +pimd_options=" -A 127.0.0.1" +ldpd_options=" -A 127.0.0.1" +nhrpd_options=" -A 127.0.0.1" +eigrpd_options=" -A 127.0.0.1" +babeld_options=" -A 127.0.0.1" +sharpd_options=" -A 127.0.0.1" +pbrd_options=" -A 127.0.0.1" +staticd_options="-A 127.0.0.1" +bfdd_options=" -A 127.0.0.1" +fabricd_options="-A 127.0.0.1" +vrrpd_options=" -A 127.0.0.1" diff --git a/ansible/router/main/templates/etc/gobgpd.conf.j2 b/ansible/router/main/templates/etc/gobgpd.conf.j2 new file mode 100644 index 0000000000000000000000000000000000000000..cb32480d0ea8e67adba7520423805da795f1f3f0 --- /dev/null +++ b/ansible/router/main/templates/etc/gobgpd.conf.j2 @@ -0,0 +1,28 @@ +# !!! +# {{ ansible_managed }} +# !!! + +[global.config] + as = 64512 + router-id = "{{ bgp.router_ip }}" + local-address-list = ["{{ bgp.router_ip }}"] + +[global.use-multiple-paths.config] + enabled = true + +{% if bgp.neighbors is defined %} +{% for neighbor in bgp.neighbors %} +[[neighbors]] + [neighbors.config] + neighbor-address = "{{ neighbor }}" + peer-as = 64512 +{% endfor %} +{% endif %} + +[zebra] + [zebra.config] + enabled = true + url = "unix:/var/run/frr/zserv.api" + redistribute-route-type-list = ["connect"] + software-name = "frr7.2" + version = 6 diff --git a/ansible/router/main/templates/etc/systemd/system/gobgpd.service.j2 b/ansible/router/main/templates/etc/systemd/system/gobgpd.service.j2 new file mode 100644 index 0000000000000000000000000000000000000000..9437f3e04dc183e628caea27c7ee22a4c9825472 --- /dev/null +++ b/ansible/router/main/templates/etc/systemd/system/gobgpd.service.j2 @@ -0,0 +1,20 @@ +# !!! +# {{ ansible_managed }} +# !!! + +[Unit] +Description=GoBGP Routing Daemon +Documentation=file:/usr/share/doc/gobgpd/getting-started.md +After=network.target syslog.service +ConditionPathExists=/etc/gobgpd.conf + +[Service] +Type=notify +ExecStartPre=/opt/gobgpd/gobgpd -f /etc/gobgpd.conf -d +ExecStart=/opt/gobgpd/gobgpd -f /etc/gobgpd.conf --sdnotify --disable-stdlog --syslog yes +ExecReload=/opt/gobgpd/gobgpd -r +AmbientCapabilities=CAP_NET_BIND_SERVICE +User=frr + +[Install] +WantedBy=multi-user.target diff --git a/ansible/router/main/vars/base.yaml b/ansible/router/main/vars/base.yaml index 751c1427185b95f216b6aba6fe902baeb2e631c0..bf98851716def1292d578ff6548a1bbd22c87298 100644 --- a/ansible/router/main/vars/base.yaml +++ b/ansible/router/main/vars/base.yaml @@ -49,4 +49,12 @@ iptables_rules_v6_file: etc/iptables/rules.v6.j2 # Playbook vars -# nope +bgp: + router_ip: "192.168.99.254" + neighbors: + - "192.168.98.11" + - "192.168.98.12" + - "192.168.98.13" + - "192.168.98.21" + - "192.168.98.22" + - "192.168.98.23"