dns_zone + knot: rename some fields + add record types

This commit is contained in:
jeltz 2022-08-18 16:32:56 +02:00
parent 86277d05c2
commit b9dd74af40
Signed by: jeltz
GPG key ID: 800882B66C0C3326
3 changed files with 61 additions and 11 deletions

View file

@ -13,10 +13,13 @@ import dns.rdatatype
import dns.rdtypes.ANY.CNAME import dns.rdtypes.ANY.CNAME
import dns.rdtypes.ANY.MX import dns.rdtypes.ANY.MX
import dns.rdtypes.ANY.NS import dns.rdtypes.ANY.NS
import dns.rdtypes.ANY.PTR
import dns.rdtypes.ANY.SOA import dns.rdtypes.ANY.SOA
import dns.rdtypes.ANY.SPF
import dns.rdtypes.ANY.TXT import dns.rdtypes.ANY.TXT
import dns.rdtypes.IN.A import dns.rdtypes.IN.A
import dns.rdtypes.IN.AAAA import dns.rdtypes.IN.AAAA
import dns.rdtypes.IN.SRV
import dns.serial import dns.serial
import dns.zone import dns.zone
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -67,14 +70,25 @@ class AAAA:
) )
@dataclasses.dataclass
class PTR:
target: dns.name.Name
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.ANY.PTR.PTR(
dns.rdataclass.IN.IN, dns.rdatatype.PTR, self.target
)
@dataclasses.dataclass @dataclasses.dataclass
class CNAME: class CNAME:
address: dns.name.Name target: dns.name.Name
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
def rdata(self) -> dns.rdata.Rdata: def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.ANY.CNAME.CNAME( return dns.rdtypes.ANY.CNAME.CNAME(
dns.rdataclass.IN.IN, dns.rdatatype.CNAME, self.address dns.rdataclass.IN.IN, dns.rdatatype.CNAME, self.target
) )
@ -82,25 +96,36 @@ class CNAME:
class MX: class MX:
exchange: Annotated[dns.name.Name, MultiRecords] exchange: Annotated[dns.name.Name, MultiRecords]
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
priority: int = 10 preference: int = 10
def rdata(self) -> dns.rdata.Rdata: def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.ANY.MX.MX( return dns.rdtypes.ANY.MX.MX(
dns.rdataclass.IN.IN, dns.rdataclass.IN.IN,
dns.rdatatype.MX, dns.rdatatype.MX,
self.priority, self.preference,
self.exchange, self.exchange,
) )
@dataclasses.dataclass @dataclasses.dataclass
class NS: class NS:
address: Annotated[dns.name.Name, MultiRecords] target: Annotated[dns.name.Name, MultiRecords]
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
def rdata(self) -> dns.rdata.Rdata: def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.ANY.NS.NS( return dns.rdtypes.ANY.NS.NS(
dns.rdataclass.IN.IN, dns.rdatatype.NS, self.address dns.rdataclass.IN.IN, dns.rdatatype.NS, self.target
)
@dataclasses.dataclass
class SPF:
data: str
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.ANY.SPF.SPF(
dns.rdataclass.IN.IN, dns.rdatatype.SPF, self.data
) )
@ -115,6 +140,25 @@ class TXT:
) )
@dataclasses.dataclass
class SRV:
target: Annotated[dns.name.Name, MultiRecords]
weight: int
port: int
priority: int = 10
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
def rdata(self) -> dns.rdata.Rdata:
return dns.rdtypes.IN.SRV.SRV(
dns.rdataclass.IN.IN,
dns.rdatatype.SRV,
self.priority,
self.weight,
self.port,
self.target,
)
@dataclasses.dataclass @dataclasses.dataclass
class SOA: class SOA:
mname: dns.name.Name mname: dns.name.Name
@ -122,7 +166,7 @@ class SOA:
refresh: int refresh: int
retry: int retry: int
expire: int expire: int
ttl: int minimum: int
serial: int = 1 serial: int = 1
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
@ -136,7 +180,7 @@ class SOA:
self.refresh, self.refresh,
self.retry, self.retry,
self.expire, self.expire,
self.ttl, self.minimum,
) )
@ -259,6 +303,9 @@ def main() -> int:
"txt": TXT, "txt": TXT,
"a": A, "a": A,
"aaaa": AAAA, "aaaa": AAAA,
"srv": SRV,
"spf": SPF,
"ptr": PTR,
"cname": CNAME, "cname": CNAME,
"mx": MX, "mx": MX,
} }

View file

@ -23,6 +23,6 @@ knotd__zones: []
knotd__soa_refresh: 1d knotd__soa_refresh: 1d
knotd__soa_retry: 2h knotd__soa_retry: 2h
knotd__soa_expire: 1000h knotd__soa_expire: 1000h
knotd__soa_ttl: 48h knotd__soa_minimum: 48h
knotd__dnssec_validation: true knotd__dnssec_validation: true
... ...

View file

@ -40,14 +40,17 @@
| community.general.to_seconds | int }}" | community.general.to_seconds | int }}"
expire: "{{ item.value.soa.expire | default(knotd__soa_expire) expire: "{{ item.value.soa.expire | default(knotd__soa_expire)
| community.general.to_seconds | int }}" | community.general.to_seconds | int }}"
ttl: "{{ item.value.soa.ttl | default(knotd__soa_ttl) minimum: "{{ item.value.soa.minimum | default(knotd__soa_minimum)
| community.general.to_seconds | int }}" | community.general.to_seconds | int }}"
hosts: "{{ item.value.hosts | default(omit) }}" hosts: "{{ item.value.hosts | default(omit) }}"
ns: "{{ item.value.ns | default(omit) }}" ns: "{{ item.value.ns | default(omit) }}"
mx: "{{ item.value.mx | default(omit) }}" mx: "{{ item.value.mx | default(omit) }}"
cname: "{{ item.value.cname | default(omit) }}" cname: "{{ item.value.cname | default(omit) }}"
txt: "{{ item.value.txt | default(omit) }}" txt: "{{ item.value.txt | default(omit) }}"
a: "{{ item.value.a | default(omit) }}" a: "{{ item.value.a | default(omit) }}"
spf: "{{ item.value.spf | default(omit) }}"
srv: "{{ item.value.srv | default(omit) }}"
ptr: "{{ item.value.ptr | default(omit) }}"
aaaa: "{{ item.value.aaaa | default(omit) }}" aaaa: "{{ item.value.aaaa | default(omit) }}"
when: "item.value.master is not defined when: "item.value.master is not defined
and (item.value.enabled | default(true))" and (item.value.enabled | default(true))"