Manage DNS servers using Ansible #93
3 changed files with 61 additions and 11 deletions
|
@ -13,10 +13,13 @@ import dns.rdatatype
|
|||
import dns.rdtypes.ANY.CNAME
|
||||
import dns.rdtypes.ANY.MX
|
||||
import dns.rdtypes.ANY.NS
|
||||
import dns.rdtypes.ANY.PTR
|
||||
import dns.rdtypes.ANY.SOA
|
||||
import dns.rdtypes.ANY.SPF
|
||||
import dns.rdtypes.ANY.TXT
|
||||
import dns.rdtypes.IN.A
|
||||
import dns.rdtypes.IN.AAAA
|
||||
import dns.rdtypes.IN.SRV
|
||||
import dns.serial
|
||||
import dns.zone
|
||||
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
|
||||
class CNAME:
|
||||
address: dns.name.Name
|
||||
target: dns.name.Name
|
||||
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
|
||||
|
||||
def rdata(self) -> dns.rdata.Rdata:
|
||||
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:
|
||||
exchange: Annotated[dns.name.Name, MultiRecords]
|
||||
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
|
||||
priority: int = 10
|
||||
preference: int = 10
|
||||
|
||||
def rdata(self) -> dns.rdata.Rdata:
|
||||
return dns.rdtypes.ANY.MX.MX(
|
||||
dns.rdataclass.IN.IN,
|
||||
dns.rdatatype.MX,
|
||||
self.priority,
|
||||
self.preference,
|
||||
self.exchange,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class NS:
|
||||
address: Annotated[dns.name.Name, MultiRecords]
|
||||
target: Annotated[dns.name.Name, MultiRecords]
|
||||
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
|
||||
|
||||
def rdata(self) -> dns.rdata.Rdata:
|
||||
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
|
||||
class SOA:
|
||||
mname: dns.name.Name
|
||||
|
@ -122,7 +166,7 @@ class SOA:
|
|||
refresh: int
|
||||
retry: int
|
||||
expire: int
|
||||
ttl: int
|
||||
minimum: int
|
||||
serial: int = 1
|
||||
name: Annotated[dns.name.Name, MultiRecords] = dns.name.empty
|
||||
|
||||
|
@ -136,7 +180,7 @@ class SOA:
|
|||
self.refresh,
|
||||
self.retry,
|
||||
self.expire,
|
||||
self.ttl,
|
||||
self.minimum,
|
||||
)
|
||||
|
||||
|
||||
|
@ -259,6 +303,9 @@ def main() -> int:
|
|||
"txt": TXT,
|
||||
"a": A,
|
||||
"aaaa": AAAA,
|
||||
"srv": SRV,
|
||||
"spf": SPF,
|
||||
"ptr": PTR,
|
||||
"cname": CNAME,
|
||||
"mx": MX,
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ knotd__zones: []
|
|||
knotd__soa_refresh: 1d
|
||||
knotd__soa_retry: 2h
|
||||
knotd__soa_expire: 1000h
|
||||
knotd__soa_ttl: 48h
|
||||
knotd__soa_minimum: 48h
|
||||
knotd__dnssec_validation: true
|
||||
...
|
||||
|
|
|
@ -40,14 +40,17 @@
|
|||
| community.general.to_seconds | int }}"
|
||||
expire: "{{ item.value.soa.expire | default(knotd__soa_expire)
|
||||
| community.general.to_seconds | int }}"
|
||||
ttl: "{{ item.value.soa.ttl | default(knotd__soa_ttl)
|
||||
| community.general.to_seconds | int }}"
|
||||
minimum: "{{ item.value.soa.minimum | default(knotd__soa_minimum)
|
||||
| community.general.to_seconds | int }}"
|
||||
hosts: "{{ item.value.hosts | default(omit) }}"
|
||||
ns: "{{ item.value.ns | default(omit) }}"
|
||||
mx: "{{ item.value.mx | default(omit) }}"
|
||||
cname: "{{ item.value.cname | default(omit) }}"
|
||||
txt: "{{ item.value.txt | 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) }}"
|
||||
when: "item.value.master is not defined
|
||||
and (item.value.enabled | default(true))"
|
||||
|
|
Loading…
Reference in a new issue