summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Klaus <andrewklaus@gmail.com>2017-08-16 12:32:13 -0600
committerBrian Coca <bcoca@users.noreply.github.com>2017-08-16 14:32:13 -0400
commitc9cfc9be07361fc4db379fa3a386a73f83198c65 (patch)
tree3901394fef62adf85351b8b03e9b1e6a72dd9677
parentb339f23485ca85b72f37112b08e7a9563123c2e3 (diff)
downloadansible-c9cfc9be07361fc4db379fa3a386a73f83198c65.tar.gz
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
-rw-r--r--lib/ansible/modules/cloud/openstack/os_recordset.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/ansible/modules/cloud/openstack/os_recordset.py b/lib/ansible/modules/cloud/openstack/os_recordset.py
index 211c3ff467..00de26ccaa 100644
--- a/lib/ansible/modules/cloud/openstack/os_recordset.py
+++ b/lib/ansible/modules/cloud/openstack/os_recordset.py
@@ -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)