[interfaces] Deploy interfaces using LDAP
parent
3d21addd34
commit
4ea6bd9687
|
@ -1,2 +1,6 @@
|
|||
interfaces:
|
||||
adm: ens18
|
||||
srv_nat: ens19
|
||||
|
||||
loc_framadate:
|
||||
path: /var/www/framadate
|
||||
|
|
|
@ -98,12 +98,15 @@ class LookupModule(LookupBase):
|
|||
result = self.base.result(query_id)
|
||||
result = result[1][0][1]
|
||||
result = [res.decode('utf-8') for res in result[attr]]
|
||||
elif terms[0] == 'networks':
|
||||
elif terms[0] == 'network':
|
||||
network = terms[1]
|
||||
query_id = self.base.search(f"cn={network},ou=networks,{self.base_dn}", ldap.SCOPE_BASE, "objectClass=ipNetwork")
|
||||
result = self.base.result(query_id)
|
||||
result = result[1][0][1]
|
||||
return [str(ipaddress.ip_network('{}/{}'.format(result['ipNetworkNumber'][0].decode('utf-8'), result['ipNetmaskNumber'][0].decode('utf-8'))))]
|
||||
return {
|
||||
'network': result['ipNetworkNumber'][0].decode('utf-8'),
|
||||
'netmask': result['ipNetmaskNumber'][0].decode('utf-8'),
|
||||
}
|
||||
elif terms[0] == 'vlanid':
|
||||
network = terms[1]
|
||||
query_id = self.base.search(f"cn={network},ou=networks,{self.base_dn}", ldap.SCOPE_BASE, "objectClass=ipNetwork")
|
||||
|
|
|
@ -1,69 +1,27 @@
|
|||
#!/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
|
||||
dns: 185.230.79.99
|
||||
- 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
|
||||
dns: 172.16.3.99
|
||||
- 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
|
||||
dns: 185.230.78.99
|
||||
- name: adh_nat
|
||||
id: 13
|
||||
dns: 100.64.0.99
|
||||
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 }}"
|
||||
|
|
|
@ -1,35 +1,41 @@
|
|||
{{ 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) %}
|
||||
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 %}
|
||||
|
||||
iface {{ item.ifnames[0] }} inet6 static
|
||||
address {{ ifconfig.ipv6[0].address }}/{{ ifconfig.ipv6[0].prefix }}
|
||||
iface {{ interfaces[item.name] }} inet6 static
|
||||
{% for ip in (ips | ipv6) %}
|
||||
address {{ ip }}/64
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
|
|
Loading…
Reference in New Issue