1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ipa_dnszone: add PTR synchronization support for dnszones (#3374)

* 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>
This commit is contained in:
Annie Lee 2021-12-27 03:35:24 -05:00 committed by GitHub
parent 9642a15d34
commit 84e45c2cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 15 deletions

View file

@ -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).

View file

@ -27,11 +27,14 @@ options:
choices: ["absent", "present"] choices: ["absent", "present"]
type: str type: str
dynamicupdate: dynamicupdate:
description: Apply dynamic update to zone description: Apply dynamic update to zone.
required: false default: false
default: "false" type: bool
choices: ["false", "true"] allowsyncptr:
type: str description: Allow synchronization of forward and reverse records in the zone.
default: false
type: bool
version_added: 4.3.0
extends_documentation_fragment: extends_documentation_fragment:
- community.general.ipa.documentation - community.general.ipa.documentation
@ -60,6 +63,14 @@ EXAMPLES = r'''
ipa_user: admin ipa_user: admin
ipa_pass: topsecret ipa_pass: topsecret
state: absent 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''' RETURN = r'''
@ -79,25 +90,37 @@ class DNSZoneIPAClient(IPAClient):
super(DNSZoneIPAClient, self).__init__(module, host, port, protocol) super(DNSZoneIPAClient, self).__init__(module, host, port, protocol)
def dnszone_find(self, zone_name, details=None): def dnszone_find(self, zone_name, details=None):
itens = {'idnsname': zone_name} items = {'all': 'true',
'idnsname': zone_name, }
if details is not None: if details is not None:
itens.update(details) items.update(details)
return self._post_json( return self._post_json(
method='dnszone_find', method='dnszone_find',
name=zone_name, name=zone_name,
item=itens item=items
) )
def dnszone_add(self, zone_name=None, details=None): def dnszone_add(self, zone_name=None, details=None):
itens = {} items = {}
if details is not None: if details is not None:
itens.update(details) items.update(details)
return self._post_json( return self._post_json(
method='dnszone_add', method='dnszone_add',
name=zone_name, 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): def dnszone_del(self, zone_name=None, record_name=None, details=None):
@ -109,18 +132,29 @@ def ensure(module, client):
zone_name = module.params['zone_name'] zone_name = module.params['zone_name']
state = module.params['state'] state = module.params['state']
dynamicupdate = module.params['dynamicupdate'] dynamicupdate = module.params['dynamicupdate']
allowsyncptr = module.params['allowsyncptr']
ipa_dnszone = client.dnszone_find(zone_name)
changed = False changed = False
# does zone exist
ipa_dnszone = client.dnszone_find(zone_name)
if state == 'present': if state == 'present':
if not ipa_dnszone: if not ipa_dnszone:
changed = True changed = True
if not module.check_mode: 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: else:
changed = False changed = False
# state is absent
else: else:
# check for generic zone existence
if ipa_dnszone: if ipa_dnszone:
changed = True changed = True
if not module.check_mode: if not module.check_mode:
@ -133,7 +167,8 @@ def main():
argument_spec = ipa_argument_spec() argument_spec = ipa_argument_spec()
argument_spec.update(zone_name=dict(type='str', required=True), argument_spec.update(zone_name=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['present', 'absent']), 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, module = AnsibleModule(argument_spec=argument_spec,