mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-11-22 23:20:24 +00:00
Merge "Add support for recordset lookup by type to prevent conflicts"
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- recordset - Look an existing recordset up by zone, name and type instead of
|
||||||
|
by zone and name only. Recordsets sharing a name with recordsets of another
|
||||||
|
type, e.g. an ``A`` recordset at the apex of a zone which shares its name
|
||||||
|
with the ``SOA`` and ``NS`` recordsets created along with the zone, could
|
||||||
|
not be created, updated or deleted because the lookup matched more than one
|
||||||
|
recordset and failed with ``More than one Recordset exists with the name``.
|
||||||
@@ -21,6 +21,9 @@ options:
|
|||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the recordset. It must be ended with name of dns zone.
|
- Name of the recordset. It must be ended with name of dns zone.
|
||||||
|
- A recordset is identified by I(zone), I(name) and I(recordset_type)
|
||||||
|
because DNS allows several recordsets to share a name as long as
|
||||||
|
their types differ.
|
||||||
required: true
|
required: true
|
||||||
type: str
|
type: str
|
||||||
records:
|
records:
|
||||||
@@ -33,6 +36,11 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Recordset type
|
- Recordset type
|
||||||
- Required when I(state=present).
|
- Required when I(state=present).
|
||||||
|
- Used to identify the recordset, together with I(zone) and I(name).
|
||||||
|
When I(state=absent) and this option is omitted, the recordset is
|
||||||
|
looked up by name only, which fails when its name carries more than
|
||||||
|
one type, e.g. at the apex of a zone where SOA and NS recordsets
|
||||||
|
share the name of the zone.
|
||||||
choices: ['a', 'aaaa', 'mx', 'cname', 'txt', 'ns', 'srv', 'ptr', 'caa']
|
choices: ['a', 'aaaa', 'mx', 'cname', 'txt', 'ns', 'srv', 'ptr', 'caa']
|
||||||
type: str
|
type: str
|
||||||
state:
|
state:
|
||||||
@@ -76,12 +84,25 @@ EXAMPLES = '''
|
|||||||
records: ['10.1.1.1']
|
records: ['10.1.1.1']
|
||||||
ttl: 7200
|
ttl: 7200
|
||||||
|
|
||||||
# Delete recordset named "www.example.net."
|
# Create a recordset at the apex of zone "example.net.", where the SOA and NS
|
||||||
|
# recordsets created with the zone share its name
|
||||||
|
- openstack.cloud.recordset:
|
||||||
|
cloud: mycloud
|
||||||
|
state: present
|
||||||
|
zone: example.net.
|
||||||
|
name: example.net.
|
||||||
|
recordset_type: "a"
|
||||||
|
records: ['10.1.1.1']
|
||||||
|
ttl: 3600
|
||||||
|
|
||||||
|
# Delete the "a" recordset named "www.example.net.", leaving recordsets of
|
||||||
|
# other types with that name untouched
|
||||||
- openstack.cloud.recordset:
|
- openstack.cloud.recordset:
|
||||||
cloud: mycloud
|
cloud: mycloud
|
||||||
state: absent
|
state: absent
|
||||||
zone: example.net.
|
zone: example.net.
|
||||||
name: www.example.net.
|
name: www.example.net.
|
||||||
|
recordset_type: "a"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
@@ -204,6 +225,18 @@ class DnsRecordsetModule(OpenStackModule):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _find_recordset(self, zone, name):
|
||||||
|
# A recordset is identified by zone, name and type: DNS allows several
|
||||||
|
# recordsets to share a name as long as their types differ, e.g. at the
|
||||||
|
# apex of a zone where the SOA and NS recordsets share the name of the
|
||||||
|
# zone. Looking a recordset up by name only would match all of them and
|
||||||
|
# fail with a DuplicateResource error.
|
||||||
|
query = {}
|
||||||
|
recordset_type = self.params['recordset_type']
|
||||||
|
if recordset_type is not None:
|
||||||
|
query['type'] = recordset_type.upper()
|
||||||
|
return self.conn.dns.find_recordset(zone, name, **query)
|
||||||
|
|
||||||
def _build_params(self):
|
def _build_params(self):
|
||||||
recordset_type = self.params['recordset_type']
|
recordset_type = self.params['recordset_type']
|
||||||
records = self.params['records']
|
records = self.params['records']
|
||||||
@@ -224,7 +257,7 @@ class DnsRecordsetModule(OpenStackModule):
|
|||||||
ttl = self.params.get('ttl')
|
ttl = self.params.get('ttl')
|
||||||
|
|
||||||
zone = self.conn.dns.find_zone(name_or_id=zone, ignore_missing=False)
|
zone = self.conn.dns.find_zone(name_or_id=zone, ignore_missing=False)
|
||||||
recordset = self.conn.dns.find_recordset(zone, name)
|
recordset = self._find_recordset(zone, name)
|
||||||
|
|
||||||
if self.ansible.check_mode:
|
if self.ansible.check_mode:
|
||||||
self.exit_json(changed=self._system_state_change(state, recordset))
|
self.exit_json(changed=self._system_state_change(state, recordset))
|
||||||
|
|||||||
Reference in New Issue
Block a user