Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipa_dnszone: add PTR synchronization support for dnszones #3374

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/3374-add-ipa-ptr-sync-support.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ipa_dnszone - add DNS zone synchronization support (https://github.com/ansible-collections/community.general/pull/3374).
ahambrick marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 41 additions & 3 deletions plugins/modules/identity/ipa/ipa_dnszone.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
default: "false"
choices: ["false", "true"]
type: str
allowsyncptr:
description: Allow synchronization of forward and reverse records in the zone.
required: false
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
default: false
choices: [false, true]
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
type: bool
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
extends_documentation_fragment:
- community.general.ipa.documentation

Expand Down Expand Up @@ -60,6 +66,14 @@
ipa_user: admin
ipa_pass: topsecret
state: absent

- name: Ensure dns zone is present and is allowing sync
community.general.ipa_dnszone:
ipa_host: spider.example.com
ipa_pass: Passw0rd!
state: present
zone_name: example.com
allowsyncptr: true
'''

RETURN = r'''
Expand All @@ -79,7 +93,8 @@ def __init__(self, module, host, port, protocol):
super(DNSZoneIPAClient, self).__init__(module, host, port, protocol)

def dnszone_find(self, zone_name, details=None):
itens = {'idnsname': zone_name}
itens = {'all': 'true',
'idnsname': zone_name, }
if details is not None:
itens.update(details)

Expand All @@ -100,6 +115,17 @@ def dnszone_add(self, zone_name=None, details=None):
item=itens
)

def dnszone_mod(self, zone_name=None, details=None):
itens = {}
ahambrick marked this conversation as resolved.
Show resolved Hide resolved
if details is not None:
itens.update(details)

return self._post_json(
method='dnszone_mod',
name=zone_name,
item=itens
)

def dnszone_del(self, zone_name=None, record_name=None, details=None):
return self._post_json(
method='dnszone_del', name=zone_name, item={})
Expand All @@ -109,18 +135,29 @@ def ensure(module, client):
zone_name = module.params['zone_name']
state = module.params['state']
dynamicupdate = module.params['dynamicupdate']
allowsyncptr = module.params['allowsyncptr']

changed = False

# does zone exist
ipa_dnszone = client.dnszone_find(zone_name)

changed = False
if state == 'present':
if not ipa_dnszone:

if not module.check_mode:
changed = True
ahambrick marked this conversation as resolved.
Show resolved Hide resolved
client.dnszone_add(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate, 'idnsallowsyncptr': allowsyncptr})
elif ipa_dnszone['idnsallowdynupdate'][0] != dynamicupdate.upper() or ipa_dnszone['idnsallowsyncptr'][0] != str(allowsyncptr).upper():
changed = True
if not module.check_mode:
client.dnszone_add(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate})
client.dnszone_mod(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate, 'idnsallowsyncptr': allowsyncptr})
else:
changed = False
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

# state is absent
else:
# check for generic zone existence
if ipa_dnszone:
changed = True
if not module.check_mode:
Expand All @@ -134,6 +171,7 @@ def main():
argument_spec.update(zone_name=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['present', 'absent']),
dynamicupdate=dict(type='str', required=False, default='false', choices=['true', 'false']),
allowsyncptr=dict(type='bool', required=False, default=False, choices=[True, False]),
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
)

module = AnsibleModule(argument_spec=argument_spec,
Expand Down