Skip to content

Commit

Permalink
ipa_dnszone: add PTR synchronization support for dnszones (#3374) (#3950
Browse files Browse the repository at this point in the history
)

* Add PTR synchronization support for dnszones

* Add changelog fragment

* Update changelogs/fragments/3374-add-ipa-ptr-sync-support.yml

Update to reflect proper module name.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/identity/ipa/ipa_dnszone.py

Add period.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/identity/ipa/ipa_dnszone.py

Remove requires comment.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Change type to boolean in following with API docs

* Tested with needed changes made.

* Fix documentation to max implementation

* Check for specific params; allow for modifications if needed

* Add PTR synchronization support for dnszones

* Add changelog fragment

* Update changelogs/fragments/3374-add-ipa-ptr-sync-support.yml

Update to reflect proper module name.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Remove trailing whitespace

* Make use of full search and compare params

* Fix formatting errors

* Move the change flag outside of module check

* Fix itens typo to items

* Update dynamicupdate to a boolean

* Remove unnecessary flags and options

* Minor comment changes

* Update changelogs/fragments/3374-add-ipa-ptr-sync-support.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/identity/ipa/ipa_dnszone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Anne-Marie Lee <alee@datainterfuse.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 84e45c2)

Co-authored-by: Annie Lee <hambriak@gmail.com>
  • Loading branch information
patchback[bot] and ahambrick authored Dec 27, 2021
1 parent 468b28b commit fe5ad99
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
3 changes: 3 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,3 @@
minor_changes:
- ipa_dnszone - add DNS zone synchronization support (https://github.com/ansible-collections/community.general/pull/3374).
- ipa_dnszone - ``dynamicupdate`` is now a boolean parameter, instead of a string parameter accepting ``"true"`` and ``"false"``. Also the module is now idempotent with respect to ``dynamicupdate`` (https://github.com/ansible-collections/community.general/pull/3374).
63 changes: 49 additions & 14 deletions plugins/modules/identity/ipa/ipa_dnszone.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
choices: ["absent", "present"]
type: str
dynamicupdate:
description: Apply dynamic update to zone
required: false
default: "false"
choices: ["false", "true"]
type: str
description: Apply dynamic update to zone.
default: false
type: bool
allowsyncptr:
description: Allow synchronization of forward and reverse records in the zone.
default: false
type: bool
version_added: 4.3.0
extends_documentation_fragment:
- community.general.ipa.documentation
Expand Down Expand Up @@ -60,6 +63,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,25 +90,37 @@ 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}
items = {'all': 'true',
'idnsname': zone_name, }
if details is not None:
itens.update(details)
items.update(details)

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

def dnszone_add(self, zone_name=None, details=None):
itens = {}
items = {}
if details is not None:
itens.update(details)
items.update(details)

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

def dnszone_mod(self, zone_name=None, details=None):
items = {}
if details is not None:
items.update(details)

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

def dnszone_del(self, zone_name=None, record_name=None, details=None):
Expand All @@ -109,18 +132,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:

changed = True
if not module.check_mode:
client.dnszone_add(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate})
client.dnszone_add(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate, 'idnsallowsyncptr': allowsyncptr})
elif ipa_dnszone['idnsallowdynupdate'][0] != str(dynamicupdate).upper() or ipa_dnszone['idnsallowsyncptr'][0] != str(allowsyncptr).upper():
changed = True
if not module.check_mode:
client.dnszone_mod(zone_name=zone_name, details={'idnsallowdynupdate': dynamicupdate, 'idnsallowsyncptr': allowsyncptr})
else:
changed = False

# state is absent
else:
# check for generic zone existence
if ipa_dnszone:
changed = True
if not module.check_mode:
Expand All @@ -133,7 +167,8 @@ def main():
argument_spec = ipa_argument_spec()
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']),
dynamicupdate=dict(type='bool', required=False, default=False),
allowsyncptr=dict(type='bool', required=False, default=False),
)

module = AnsibleModule(argument_spec=argument_spec,
Expand Down

0 comments on commit fe5ad99

Please sign in to comment.