From 59270dd41a0f752224be8edeb2c78e14dfcb9bc5 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 26 Jun 2020 17:40:41 +0300 Subject: [PATCH] Add staticd configuration This change makes possible to configure staticd routes with both integrated and standalone configuration types. Change-Id: I7d0e652748e3e88c08fc5249fd3fe6535cb4c65e --- defaults/main.yml | 3 +++ tasks/frr_post_install.yml | 35 +++++++++++++++++++++++++++++++++++ tasks/main.yml | 3 +++ templates/frr.conf.j2 | 13 +++++++++++++ tests/test.yml | 16 +++++++++++++++- tests/test_vars.yml | 3 +++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tasks/frr_post_install.yml create mode 100644 templates/frr.conf.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 9f1a199..573fb92 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -26,3 +26,6 @@ # up: route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 # down: route del -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 frr_vlans: [] + +frr_integrated_config_path: /etc/frr/frr.conf +frr_staticd_routes: [] diff --git a/tasks/frr_post_install.yml b/tasks/frr_post_install.yml new file mode 100644 index 0000000..1d1727d --- /dev/null +++ b/tasks/frr_post_install.yml @@ -0,0 +1,35 @@ +--- +# Copyright 2020, VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Configure frr + become: true + become_user: root + block: + - name: Enable integrated config + lineinfile: + create: yes + path: /etc/frr/vtysh.conf + regexp: '^(no)?\s?service integrated-vtysh-config$' + line: "service integrated-vtysh-config" + notify: Restart frr + + - name: Write down integrated config + template: + src: frr.conf.j2 + dest: "{{ frr_integrated_config_path }}" + owner: frr + group: frr + mode: "0640" + notify: Restart frr diff --git a/tasks/main.yml b/tasks/main.yml index c50e542..3c77a13 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -22,3 +22,6 @@ - name: Install frr include_tasks: frr_install.yml + +- name: Service configuration + include_tasks: frr_post_install.yml diff --git a/templates/frr.conf.j2 b/templates/frr.conf.j2 new file mode 100644 index 0000000..c354993 --- /dev/null +++ b/templates/frr.conf.j2 @@ -0,0 +1,13 @@ +! +! Zebra configuration +! +frr defaults traditional +! +hostname {{ ansible_hostname }} +log syslog informational +! +! staticd config +{{ frr_staticd_routes | join('\n') }} +! +line vty +! \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index fd77289..b4f731f 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -17,13 +17,14 @@ hosts: all vars_files: - test_vars.yml + roles: - frrouting post_tasks: - name: wait after service restart pause: - seconds: 30 + seconds: 10 - name: Ping vlans ip address shell: | @@ -43,3 +44,16 @@ fail: msg: frr is not up when: ansible_facts.services['frr'].state != 'running' + + - name: Get static routes + become: true + become_user: root + command: "vtysh -c 'show ip route'" + register: _frr_get_routes + changed_when: false + + - name: Fail if we're missing routes + fail: + msg: "We can't find route {{ item }}" + with_items: "{{ frr_staticd_routes }}" + when: item.split(' ')[-1] not in _frr_get_routes.stdout diff --git a/tests/test_vars.yml b/tests/test_vars.yml index 8ffc978..efe820f 100644 --- a/tests/test_vars.yml +++ b/tests/test_vars.yml @@ -20,3 +20,6 @@ frr_vlans: netmask: 255.255.255.0 network: 192.168.1.0 broadcast: 192.168.1.255 + +frr_staticd_routes: + - ip route 10.0.0.0/24 192.168.1.10