|
|
|
@ -20,9 +20,11 @@ import dns.rdtypes.ANY.TXT
|
|
|
|
|
import dns.rdtypes.IN.A
|
|
|
|
|
import dns.rdtypes.IN.AAAA
|
|
|
|
|
import dns.rdtypes.IN.SRV
|
|
|
|
|
import dns.reversename
|
|
|
|
|
import dns.serial
|
|
|
|
|
import dns.zone
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
from ansible.module_utils.common.validation import check_type_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RName(dns.name.Name):
|
|
|
|
@ -250,12 +252,20 @@ def product_dict(dct, keys=None):
|
|
|
|
|
|
|
|
|
|
def make_hosts_records(hosts):
|
|
|
|
|
for host, addrs in hosts.items():
|
|
|
|
|
for addr in addrs:
|
|
|
|
|
for addr in check_type_list(addrs):
|
|
|
|
|
name = dns.name.from_text(host, origin=dns.name.empty)
|
|
|
|
|
decoded = ipaddress.ip_address(addr)
|
|
|
|
|
yield AAAA(addr, name) if decoded.version == 6 else A(addr, name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_reverse_hosts_records(hosts):
|
|
|
|
|
for host, addrs in hosts.items():
|
|
|
|
|
for addr in check_type_list(addrs):
|
|
|
|
|
name = dns.name.from_text(host)
|
|
|
|
|
reverse = dns.reversename.from_address(addr)
|
|
|
|
|
yield PTR(name, reverse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_records(args, ty):
|
|
|
|
|
# TODO: Ça n'est pas du tout élégant, mais :
|
|
|
|
|
# 1. je n'ai pas réussi à spécifier dans `argument_spec` un type tiers
|
|
|
|
@ -321,6 +331,7 @@ def main() -> int:
|
|
|
|
|
"options": spec_options_of_type(SOA),
|
|
|
|
|
},
|
|
|
|
|
"hosts": {"type": "dict", "default": {}},
|
|
|
|
|
"reverse_hosts": {"type": "dict", "default": {}},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, ty in record_types.items():
|
|
|
|
@ -348,6 +359,7 @@ def main() -> int:
|
|
|
|
|
|
|
|
|
|
records = itertools.chain(
|
|
|
|
|
make_records(module.params["soa"], SOA),
|
|
|
|
|
make_reverse_hosts_records(module.params["reverse_hosts"]),
|
|
|
|
|
make_hosts_records(module.params["hosts"]),
|
|
|
|
|
itertools.chain.from_iterable(
|
|
|
|
|
itertools.chain.from_iterable(
|
|
|
|
|