From c7c3317689ef1d5de1534b8a5c6cec34fce5e2a7 Mon Sep 17 00:00:00 2001 From: Sergey Bubnov Date: Tue, 4 Jun 2019 20:07:01 +0400 Subject: [PATCH] use etcnet to configure PBR --- roles/common/tasks/configure_nics.yml | 13 ++++++++++--- roles/common/templates/pbr_config.j2 | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 roles/common/templates/pbr_config.j2 diff --git a/roles/common/tasks/configure_nics.yml b/roles/common/tasks/configure_nics.yml index 023814c..f148dd5 100644 --- a/roles/common/tasks/configure_nics.yml +++ b/roles/common/tasks/configure_nics.yml @@ -39,10 +39,17 @@ lineinfile: path: /etc/iproute2/rt_tables line: "{{ (tbl_id | int) + 200 }} tbl_{{nic.key}}" + notify: restart network + - name: "create config for {{nic.key}}" + file: + path: "/etc/net/ifaces/{{nic.key}}" + state: directory - name: define routing rules - shell: | - ip rule add from {{item|ipaddr('address')}}/{{item|ipaddr('prefix')}} lookup tbl_{{nic.key}} || /bin/true - ip route add default via {{nic.value.default}} dev {{nic.key}} table tbl_{{nic.key}} || /bin/true + template: + src: pbr_config.j2 + dest: "/etc/net/ifaces/{{nic.key}}/ifup-post" + mode: '0755' with_items: "{{nic.value.ipv4}}" + notify: restart network when: nic.value.ipv4 is defined and nic.value.default is defined when: node.net | length > 1 and nic.value.descr == 'priv' diff --git a/roles/common/templates/pbr_config.j2 b/roles/common/templates/pbr_config.j2 new file mode 100644 index 0000000..0dc0dde --- /dev/null +++ b/roles/common/templates/pbr_config.j2 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +ip rule add from {{item|ipaddr('address')}}/{{item|ipaddr('prefix')}} lookup tbl_{{nic.key}} || /bin/true +ip route add default via {{nic.value.default}} dev {{nic.key}} table tbl_{{nic.key}} || /bin/true