Skip to content
Snippets Groups Projects
Commit a82d7700 authored by shirenn's avatar shirenn 🌊
Browse files

[slapd] Filter ipv4s responsibly

parent 02df5674
No related branches found
No related tags found
1 merge request!221[slapd] Filter ipv4s responsibly
---
glob_slapd:
master_ip: "{{ query('ldap', 'ipv4', 'tealc', 'adm') | first }}"
master_ip: "{{ query('ldap', 'ip', 'tealc', 'adm') | ipv4 | first }}"
regex: "^(role:(dhcp|dns|dns-primary|dns-secondary|ftp|gitlab|miroir|ntp|pve|radius|backup)|ecdsa-sha2-nistp256:.*|ssh-(ed25519|dss|rsa):.*)$"
replication_credentials: "{{ vault_ldap_replication_credentials }}"
private_key: "{{ vault_ldap_private_key }}"
......
---
loc_slapd:
ip: "{{ query('ldap', 'ipv4', 'daniel', 'adm') | first }}"
ip: "{{ query('ldap', 'ip', 'daniel', 'adm') | ipv4 | first }}"
replica: true
replica_rid: 2
---
loc_slapd:
ip: "{{ query('ldap', 'ipv4', 'jack', 'adm') | first }}"
ip: "{{ query('ldap', 'ip', 'jack', 'adm') | ipv4 | first }}"
replica: true
replica_rid: 3
---
loc_slapd:
ip: "{{ query('ldap', 'ipv4', 'sam', 'adm') | first }}"
ip: "{{ query('ldap', 'ip', 'sam', 'adm') | ipv4 | first }}"
replica: true
replica_rid: 1
---
loc_slapd:
ip: "{{ query('ldap', 'ipv4', 'sputnik', 'adm') | first }}"
ip: "{{ query('ldap', 'ip', 'sputnik', 'adm') | ipv4 | first }}"
replica: true
replica_rid: 4
......@@ -2,5 +2,5 @@ loc_postgresql:
version: 11
loc_slapd:
ip: 172.16.10.1
ip: "{{ query('ldap', 'ip', 'tealc', 'adm') | ipv4 | first }}"
replica: false
......@@ -61,7 +61,7 @@ irc.adm.crans.org
[keepalived:children]
routeurs_vm
[ldap_server]
[slapd]
tealc.adm.crans.org
sam.adm.crans.org
daniel.adm.crans.org
......
......@@ -60,21 +60,6 @@ class LookupModule(LookupBase):
result = [res.decode('utf-8') for res in result['ipHostNumber']]
return result
def ipv4(self, host, vlan):
if isinstance(vlan, int):
network_query_id = self.base.search(f"ou=networks,{self.base_dn}", ldap.SCOPE_ONELEVEL, f"description={vlan}")
network_result = self.base.result(network_query_id)
vlan = network_result[1][0][1]['cn'][0].decode('utf-8')
if vlan == 'srv':
query_id = self.base.search(f"cn={host}.crans.org,cn={host},ou=hosts,{self.base_dn}", ldap.SCOPE_BASE)
else:
query_id = self.base.search(f"cn={host}.{vlan}.crans.org,cn={host},ou=hosts,{self.base_dn}", ldap.SCOPE_BASE)
result = self.base.result(query_id)
result = result[1][0][1]
result = [res.decode('utf-8') for res in result['ipHostNumber']]
result = [ res for res in result if type(ipaddress.ip_address(res)) is ipaddress.IPv4Address ]
return result
def all_ip(self, host):
"""
Retrieve all IP addresses of a device
......@@ -156,8 +141,6 @@ class LookupModule(LookupBase):
result = self.query(*terms[1:])
elif terms[0] == 'ip':
result = self.ip(*terms[1:])
elif terms[0] == 'ipv4':
result = self.ipv4(*terms[1:])
elif terms[0] == 'all_ip':
result = self.all_ip(*terms[1:])
elif terms[0] == 'cn':
......
#!/usr/bin/env ansible-playbook
---
- hosts: ldap_server
- hosts: slapd
vars:
slapd: '{{ glob_slapd | default({}) | combine(loc_slapd | default({})) }}'
roles:
......
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