From 80f0d3686fed6d8b0c495fbddf0c5edef3c3b61d Mon Sep 17 00:00:00 2001
From: Benjamin Graillot <graillot@crans.org>
Date: Tue, 11 Aug 2020 18:43:39 +0200
Subject: [PATCH] [quagga] Merge ipv4 and ipv6

---
 plays/firewall.yml                            | 17 ++++++++++++
 roles/quagga-ipv4/tasks/main.yml              | 16 ------------
 .../quagga-ipv4/templates/quagga/bgpd.conf.j2 | 11 --------
 roles/quagga-ipv6/tasks/main.yml              | 16 ------------
 .../quagga-ipv6/templates/quagga/bgpd.conf.j2 | 13 ----------
 .../templates/quagga/zebra.conf.j2            | 10 -------
 roles/quagga/tasks/main.yml                   | 26 +++++++++++++++----
 roles/quagga/templates/quagga/bgpd.conf.j2    | 16 ++++++++++++
 .../templates/quagga/zebra.conf.j2            |  0
 9 files changed, 54 insertions(+), 71 deletions(-)
 delete mode 100644 roles/quagga-ipv4/tasks/main.yml
 delete mode 100644 roles/quagga-ipv4/templates/quagga/bgpd.conf.j2
 delete mode 100644 roles/quagga-ipv6/tasks/main.yml
 delete mode 100644 roles/quagga-ipv6/templates/quagga/bgpd.conf.j2
 delete mode 100644 roles/quagga-ipv6/templates/quagga/zebra.conf.j2
 create mode 100644 roles/quagga/templates/quagga/bgpd.conf.j2
 rename roles/{quagga-ipv4 => quagga}/templates/quagga/zebra.conf.j2 (100%)

diff --git a/plays/firewall.yml b/plays/firewall.yml
index 7f489e63..37f9c396 100755
--- a/plays/firewall.yml
+++ b/plays/firewall.yml
@@ -14,3 +14,20 @@
       service_password: "{{ vault_re2o_service_password }}"
   roles:
     - firewall
+
+# Deploy BGP server configuration on IPv4 routers
+- hosts: crans_routeurs
+  vars:
+    zebra:
+      password: "{{ vault_zebra_password }}"
+    bgp:
+      as: 204515
+      router_id_v4: 158.255.113.73
+      network_v4: 185.230.76.0/22
+      neighbor_v4: 158.255.113.72
+      router_id_v6: 138.231.136.200
+      network_v6: 2a0c:700::/32
+      neighbor_v6: 2001:1b48:2:103::bb:1
+      remote_as: 8218
+  roles:
+    - quagga
diff --git a/roles/quagga-ipv4/tasks/main.yml b/roles/quagga-ipv4/tasks/main.yml
deleted file mode 100644
index 1da2c63b..00000000
--- a/roles/quagga-ipv4/tasks/main.yml
+++ /dev/null
@@ -1,16 +0,0 @@
----
-- name: Deploy quagga bgpd configuration
-  template:
-    src: quagga/bgpd.conf.j2
-    dest: /etc/quagga/bgpd.conf
-    mode: 0640
-    owner: quagga
-    group: quagga
-
-- name: Deploy quagga zabra configuration
-  template:
-    src: quagga/zebra.conf.j2
-    dest: /etc/quagga/zebra.conf
-    mode: 0640
-    owner: quagga
-    group: quagga
diff --git a/roles/quagga-ipv4/templates/quagga/bgpd.conf.j2 b/roles/quagga-ipv4/templates/quagga/bgpd.conf.j2
deleted file mode 100644
index d87269e3..00000000
--- a/roles/quagga-ipv4/templates/quagga/bgpd.conf.j2
+++ /dev/null
@@ -1,11 +0,0 @@
-{{ ansible_header | comment(decoration='! ') }}
-
-router bgp {{ bgp.as }}
-no synchronization
-bgp router-id {{ bgp.router_id }}
-network {{ bgp.network }}
-neighbor {{ bgp.neighbor }} remote-as {{ bgp.remote_as }}
-
-!
-log file /var/log/quagga/bgpd.log
-log stdout
diff --git a/roles/quagga-ipv6/tasks/main.yml b/roles/quagga-ipv6/tasks/main.yml
deleted file mode 100644
index 1da2c63b..00000000
--- a/roles/quagga-ipv6/tasks/main.yml
+++ /dev/null
@@ -1,16 +0,0 @@
----
-- name: Deploy quagga bgpd configuration
-  template:
-    src: quagga/bgpd.conf.j2
-    dest: /etc/quagga/bgpd.conf
-    mode: 0640
-    owner: quagga
-    group: quagga
-
-- name: Deploy quagga zabra configuration
-  template:
-    src: quagga/zebra.conf.j2
-    dest: /etc/quagga/zebra.conf
-    mode: 0640
-    owner: quagga
-    group: quagga
diff --git a/roles/quagga-ipv6/templates/quagga/bgpd.conf.j2 b/roles/quagga-ipv6/templates/quagga/bgpd.conf.j2
deleted file mode 100644
index 5021cade..00000000
--- a/roles/quagga-ipv6/templates/quagga/bgpd.conf.j2
+++ /dev/null
@@ -1,13 +0,0 @@
-{{ ansible_header | comment(decoration='! ') }}
-
-router bgp {{ bgp.as }}
-no synchronization
-bgp router-id {{ bgp.router_id }}
-neighbor {{ bgp.neighbor }} remote-as {{ bgp.remote_as }}
-address-family ipv6
-network {{ bgp.network }}
-neighbor {{ bgp.neighbor }} activate
-exit-address-family
-!
-log file /var/log/quagga/bgpd.log
-log stdout
diff --git a/roles/quagga-ipv6/templates/quagga/zebra.conf.j2 b/roles/quagga-ipv6/templates/quagga/zebra.conf.j2
deleted file mode 100644
index 1db5e12d..00000000
--- a/roles/quagga-ipv6/templates/quagga/zebra.conf.j2
+++ /dev/null
@@ -1,10 +0,0 @@
-{{ ansible_header | comment(decoration='! ') }}
-
-hostname zebra
-password {{ zebra.password }}
-enable password {{ zebra.password }}
-log file /var/log/quagga/zebra.log
-
-
-interface lo
-line vty
diff --git a/roles/quagga/tasks/main.yml b/roles/quagga/tasks/main.yml
index 054401f1..42fff5d4 100644
--- a/roles/quagga/tasks/main.yml
+++ b/roles/quagga/tasks/main.yml
@@ -8,6 +8,14 @@
   retries: 3
   until: apt_result is succeeded
 
+- name: Create quagga log directory
+  file:
+    path: /var/log/quagga
+    state: directory
+    mode: 0755
+    owner: quagga
+    group: quagga
+
 - name: Deploy quagga daemons configuration
   template:
     src: quagga/daemons.j2
@@ -24,10 +32,18 @@
     owner: quagga
     group: quagga
 
-- name: Create quagga log directory
-  file:
-    path: /var/log/quagga
-    state: directory
-    mode: 0755
+- name: Deploy quagga bgpd configuration
+  template:
+    src: quagga/bgpd.conf.j2
+    dest: /etc/quagga/bgpd.conf
+    mode: 0640
+    owner: quagga
+    group: quagga
+
+- name: Deploy quagga zabra configuration
+  template:
+    src: quagga/zebra.conf.j2
+    dest: /etc/quagga/zebra.conf
+    mode: 0640
     owner: quagga
     group: quagga
diff --git a/roles/quagga/templates/quagga/bgpd.conf.j2 b/roles/quagga/templates/quagga/bgpd.conf.j2
new file mode 100644
index 00000000..cde7878b
--- /dev/null
+++ b/roles/quagga/templates/quagga/bgpd.conf.j2
@@ -0,0 +1,16 @@
+{{ ansible_header | comment(decoration='! ') }}
+!
+router bgp {{ bgp.as }}
+ no synchronization
+ bgp router-id {{ bgp.router_id_v4 }}
+ network {{ bgp.network_v4 }}
+ neighbor {{ bgp.neighbor_v4 }} remote-as {{ bgp.remote_as }}
+!
+router bgp {{ bgp.as }}
+ no synchronization
+ bgp router-id {{ bgp.router_id_v6 }}
+ network {{ bgp.network_v6 }}
+ neighbor {{ bgp.neighbor_v6 }} remote-as {{ bgp.remote_as }}
+!
+log file /var/log/quagga/bgpd.log
+log stdout
diff --git a/roles/quagga-ipv4/templates/quagga/zebra.conf.j2 b/roles/quagga/templates/quagga/zebra.conf.j2
similarity index 100%
rename from roles/quagga-ipv4/templates/quagga/zebra.conf.j2
rename to roles/quagga/templates/quagga/zebra.conf.j2
-- 
GitLab