mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
os_recordset fix for names with multiple DNS record types (#19588)
* Fix for os_recordset.py to filter based on record type. Fixes https://github.com/ansible/ansible/issues/19572 * remove redundant variable * Needing to use recordset ID to update and delete records. Using the record name for update/delete causes issues when A and AAAA records exist for a name * Adding exception handling for dictionary item
This commit is contained in:
parent
b339f23485
commit
c9cfc9be07
1 changed files with 16 additions and 4 deletions
|
@ -189,11 +189,22 @@ def main():
|
|||
|
||||
try:
|
||||
cloud = shade.openstack_cloud(**module.params)
|
||||
recordset = cloud.get_recordset(zone, name + '.' + zone)
|
||||
recordset_type = module.params.get('recordset_type')
|
||||
recordset_filter = { 'type': recordset_type }
|
||||
|
||||
recordsets = cloud.search_recordsets(zone, name_or_id=name + '.' + zone, filters=recordset_filter)
|
||||
|
||||
if len(recordsets) == 1:
|
||||
recordset = recordsets[0]
|
||||
try:
|
||||
recordset_id = recordset['id']
|
||||
except KeyError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
# recordsets is filtered by type and should never be more than 1 return
|
||||
recordset = None
|
||||
|
||||
if state == 'present':
|
||||
recordset_type = module.params.get('recordset_type')
|
||||
records = module.params.get('records')
|
||||
description = module.params.get('description')
|
||||
ttl = module.params.get('ttl')
|
||||
|
@ -219,10 +230,11 @@ def main():
|
|||
zone, pre_update_recordset)
|
||||
if changed:
|
||||
zone = cloud.update_recordset(
|
||||
zone, name + '.' + zone,
|
||||
zone, recordset_id,
|
||||
records=records,
|
||||
description=description,
|
||||
ttl=ttl)
|
||||
|
||||
module.exit_json(changed=changed, recordset=recordset)
|
||||
|
||||
elif state == 'absent':
|
||||
|
@ -235,7 +247,7 @@ def main():
|
|||
if recordset is None:
|
||||
changed=False
|
||||
else:
|
||||
cloud.delete_recordset(zone, name + '.' + zone)
|
||||
cloud.delete_recordset(zone, recordset_id)
|
||||
changed=True
|
||||
module.exit_json(changed=changed)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue