From e9fdfde4174da27e36081379d76a4e73e04cd53e Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Mon, 20 Apr 2020 18:56:42 +0200 Subject: [PATCH] [interfaces] Deploy /etc/network/interfaces for adm --- interfaces.yml | 12 ++++++++++++ roles/interfaces/tasks/main.yml | 7 +++++++ .../templates/network/interfaces.d/02-adm.j2 | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100755 interfaces.yml create mode 100644 roles/interfaces/tasks/main.yml create mode 100644 roles/interfaces/templates/network/interfaces.d/02-adm.j2 diff --git a/interfaces.yml b/interfaces.yml new file mode 100755 index 00000000..0d028edc --- /dev/null +++ b/interfaces.yml @@ -0,0 +1,12 @@ +#!/usr/bin/env ansible-playbook +--- +# Set variable adm_iface for all servers +- hosts: server + tasks: + - shell: grep adm /sys/class/net/*/ifalias | sed "s|/sys/class/net/||" | sed "s|/ifalias:.*||" + register: adm_iface + check_mode: no + +- hosts: boeing.adm.crans.org + roles: + - interfaces diff --git a/roles/interfaces/tasks/main.yml b/roles/interfaces/tasks/main.yml new file mode 100644 index 00000000..095878e4 --- /dev/null +++ b/roles/interfaces/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- name: Deploy adm interface config + template: + src: network/interfaces.d/02-adm.j2 + dest: /etc/network/interfaces.d/02-adm + mode: 0644 + when: adm_iface.stdout diff --git a/roles/interfaces/templates/network/interfaces.d/02-adm.j2 b/roles/interfaces/templates/network/interfaces.d/02-adm.j2 new file mode 100644 index 00000000..79cbe5fa --- /dev/null +++ b/roles/interfaces/templates/network/interfaces.d/02-adm.j2 @@ -0,0 +1,17 @@ +{{ ansible_header | comment }} + +allow-hotplug {{ adm_iface.stdout }} +iface {{ adm_iface.stdout }} inet static + address {{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv4.address }} + network {{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv4.network }} + netmask {{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv4.netmask }} + broadcast {{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv4.broadcast }} + dns-nameservers 10.231.136.152 10.231.136.4 + dns-search adm.crans.org + up /sbin/ip link set $IFACE alias adm + +iface {{ adm_iface.stdout }} inet6 static + address {{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv6[0].address }}/{{ hostvars[inventory_hostname]['ansible_' + adm_iface.stdout].ipv6[0].prefix }} + autoconf 1 + accept_ra 2 + up /sbin/sysctl net/ipv6/conf/$IFACE/accept_ra_defrtr=1