dns_zone + knotd: add 'reverse_hosts' option

dns
jeltz 2 years ago
parent 4a29c317a5
commit 126d0f49df
Signed by: jeltz
GPG Key ID: 800882B66C0C3326

@ -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(

@ -43,6 +43,7 @@
minimum: "{{ item.value.soa.minimum | default(knotd__soa_minimum)
| community.general.to_seconds | int }}"
hosts: "{{ item.value.hosts | default(omit) }}"
reverse_hosts: "{{ item.value.reverse_hosts | default(omit) }}"
ns: "{{ item.value.ns | default(omit) }}"
mx: "{{ item.value.mx | default(omit) }}"
cname: "{{ item.value.cname | default(omit) }}"

Loading…
Cancel
Save