Skip to content
Snippets Groups Projects
Commit 59f73fed authored by Benjamin Graillot's avatar Benjamin Graillot
Browse files

Merge branch 'interfaces' into 'newinfra'

Interfaces

See merge request !73
parents 54b67cac 22dee4e7
No related branches found
No related tags found
1 merge request!73Interfaces
interfaces:
adm: ens18
srv_nat: ens19
loc_framadate:
path: /var/www/framadate
#!/usr/bin/env ansible-playbook
---
# Get ifname of configured vlan for all servers
- hosts: server
tasks:
- shell: "grep {{ item }} /sys/class/net/*/ifalias | sed \"s|/sys/class/net/||\" | sed \"s|/ifalias:.*||\""
check_mode: false
register: ifaces
loop:
- srv
- ens
- adm
- borne
- switch
- fil
- hosts: boeing.adm.crans.org,cochon.adm.crans.org,tracker.adm.crans.org,voyager.adm.crans.org,lutim.adm.crans.org,gateau.adm.crans.org,owncloud-srv.adm.crans.org,charybde.adm.crans.org,cas-srv.adm.crans.org,fyre.adm.crans.org,silice.adm.crans.org,frontdaur.adm.crans.org,bakdaur.adm.crans.org,ethercalc-srv.adm.crans.org,alice.adm.crans.org,mailman.adm.crans.org
- hosts: voyager.adm.crans.org
vars:
vlan:
- name: srv
id: 0
metric: 100
gateway: 185.230.79.254
dns: 185.230.79.152 185.230.79.4
dns_search: crans.org
ifnames: "{{ ifaces | json_query('results[?item==`srv`].stdout') }}"
- name: ens
id: 1
metric: 300
gateway: 138.231.136.254
dns: 138.231.136.152 138.231.136.4
dns_search: crans.org
ifnames: "{{ ifaces | json_query('results[?item==`ens`].stdout') }}"
- name: adm
id: 2
dns: 10.231.136.152 10.231.136.4
dns_search: adm.crans.org
ifnames: "{{ ifaces | json_query('results[?item==`adm`].stdout') }}"
- name: borne
gateway: 185.230.79.99
dns: 185.230.79.99
gateway_v6: 2a0c:700:2::ff:fe00:9902
- name: srv_nat
id: 3
dns: 10.231.148.52 10.231.148.4
dns_search: borne.crans.org
ifnames: "{{ ifaces | json_query('results[?item==`borne`].stdout') }}"
- name: switch
gateway: 172.16.3.99
dns: 172.16.3.99
gateway_v6: 2a0c:700:3::ff:fe00:9903
- name: san
id: 4
dns: 10.231.100.152 10.231.100.4
dns_search: switch.crans.org
ifnames: "{{ ifaces | json_query('results[?item==`switch`].stdout') }}"
- name: fil
id: 21
metric: 400
gateway: 10.54.0.254
dns: 10.54.0.152 10.54.0.4
dns_search: fil.crans.org
ifnames: "{{ ifaces | json_query('results[?item==`fil`].stdout') }}"
- name: adm
id: 10
dns: 172.16.10.101 172.16.10.102
- name: infra
id: 11
dns: 172.16.32.99
- name: adh
id: 23
metric: 200
gateway: 185.230.78.254
dns: 185.230.78.152 185.230.78.4
dns_search: crans.org
ifnames: "{{ ifaces | json_query('results[?item==`adh`].stdout') }}"
roles: ["interfaces"]
id: 12
gateway: 185.230.78.99
dns: 185.230.78.99
gateway_v6: 2a0c:700:12::ff:fe00:9912
- name: adh_nat
id: 13
gateway: 100.64.0.99
dns: 100.64.0.99
gateway_v6: 2a0c:700:13::ff:fe00:9913
roles:
- interfaces
......@@ -17,7 +17,7 @@
- name: Deploy interfaces config
template:
src: "network/interfaces.d/ifalias.j2"
dest: "/etc/network/interfaces.d/{{ '%02d' | format(item.id) }}-{{ item.name }}"
dest: "/etc/network/interfaces.d/{{ '%02d' | format(item.id) }}-{{ item.name | replace('_', '-') }}"
mode: 0644
when: (item.ifnames | length > 0) and item.ifnames[0] != ''
when: item.name in interfaces
loop: "{{ vlan }}"
{{ ansible_header | comment }}
{% set ifconfig = hostvars[inventory_hostname]['ansible_' + item.ifnames[0]] %}
auto {{ item.ifnames[0] }}
iface {{ item.ifnames[0] }} inet static
address {{ ifconfig.ipv4.address }}
network {{ ifconfig.ipv4.network }}
netmask {{ ifconfig.ipv4.netmask }}
broadcast {{ ifconfig.ipv4.broadcast }}
{% set vlan_name = (item.name | replace('_', '-')) %}
{% set subnet = query('ldap', 'network', vlan_name) %}
{% set ips = query('ldap', 'ip', ansible_hostname, vlan_name) %}
{% if (ips | ipv4 | length) > 0 %}
auto {{ interfaces[item.name] }}
iface {{ interfaces[item.name] }} inet static
{% for ip in (ips | ipv4) %}
address {{ ip }}
{% endfor %}
network {{ subnet.network }}
netmask {{ subnet.netmask }}
{% if item.gateway is defined %}
gateway {{ item.gateway }}
{% endif %}
{% if item.metric is defined %}
metric {{ item.metric }}
{% endif %}
mtu 1496
{% if item.dns is defined %}
dns-nameservers {{ item.dns }}
dns-search {{ item.dns_search }}
up /sbin/ip link set $IFACE alias {{ item.name }}
{% endif %}
dns-search {{ vlan_name }}.crans.org
up /sbin/ip link set $IFACE alias {{ vlan_name }}
{% if ansible_local.interfaces.sup_if_4 is defined %}
{% if item.ifnames[0] in ansible_local.interfaces.sup_if_4 %}
{% for line in ansible_local.interfaces.sup_if_4[item.ifnames[0]] %}
{% if interfaces[item.name] in ansible_local.interfaces.sup_if_4 %}
{% for line in ansible_local.interfaces.sup_if_4[interfaces[item.name]] %}
{{ line }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
iface {{ item.ifnames[0] }} inet6 static
address {{ ifconfig.ipv6[0].address }}/{{ ifconfig.ipv6[0].prefix }}
{% if (ips | ipv6 | length) > 0 %}
iface {{ interfaces[item.name] }} inet6 static
{% for ip in (ips | ipv6) %}
address {{ ip }}/64
{% endfor %}
{% if item.gateway_v6 is defined %}
gateway {{ item.gateway_v6 }}
{% endif %}
{% if ansible_local.interfaces.sup_if_6 is defined %}
{% if item.ifnames[0] in ansible_local.interfaces.sup_if_6 %}
{% for line in ansible_local.interfaces.sup_if_6[item.ifnames[0]] %}
{% if interfaces[item.name] in ansible_local.interfaces.sup_if_6 %}
{% for line in ansible_local.interfaces.sup_if_6[interfaces[item.name]] %}
{{ line }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment