Adds overwrite option to rax_dns_record
This commit is contained in:
parent
fcea4e1884
commit
b3066fcff7
1 changed files with 17 additions and 5 deletions
|
@ -44,6 +44,12 @@ options:
|
||||||
description:
|
description:
|
||||||
- FQDN record name to create
|
- FQDN record name to create
|
||||||
required: True
|
required: True
|
||||||
|
overwrite:
|
||||||
|
description:
|
||||||
|
- Add new records if data doesn't match, instead of updating existing
|
||||||
|
record with matching name. If there are already multiple records with
|
||||||
|
matching name and overwrite=true, this module will fail.
|
||||||
|
default: false
|
||||||
priority:
|
priority:
|
||||||
description:
|
description:
|
||||||
- Required for MX and SRV records, but forbidden for other record types.
|
- Required for MX and SRV records, but forbidden for other record types.
|
||||||
|
@ -184,7 +190,8 @@ def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None,
|
||||||
|
|
||||||
|
|
||||||
def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
|
def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
|
||||||
priority=None, record_type='A', state='present', ttl=7200):
|
overwrite=False, priority=None, record_type='A',
|
||||||
|
state='present', ttl=7200):
|
||||||
"""Function for manipulating record types other than PTR"""
|
"""Function for manipulating record types other than PTR"""
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -206,9 +213,12 @@ def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
|
||||||
module.fail_json(msg='%s' % e.message)
|
module.fail_json(msg='%s' % e.message)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
record = domain.find_record(record_type, name=name)
|
if overwrite:
|
||||||
|
record = domain.find_record(record_type, name=name)
|
||||||
|
else:
|
||||||
|
record = domain.find_record(record_type, name=name, data=data)
|
||||||
except pyrax.exceptions.DomainRecordNotUnique, e:
|
except pyrax.exceptions.DomainRecordNotUnique, e:
|
||||||
module.fail_json(msg='%s' % e.message)
|
module.fail_json(msg='overwrite=true and there are multiple matching records')
|
||||||
except pyrax.exceptions.DomainRecordNotFound, e:
|
except pyrax.exceptions.DomainRecordNotFound, e:
|
||||||
try:
|
try:
|
||||||
record_data = {
|
record_data = {
|
||||||
|
@ -278,6 +288,7 @@ def main():
|
||||||
domain=dict(),
|
domain=dict(),
|
||||||
loadbalancer=dict(),
|
loadbalancer=dict(),
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
|
overwrite=dict(type='bool', default=True),
|
||||||
priority=dict(type='int'),
|
priority=dict(type='int'),
|
||||||
server=dict(),
|
server=dict(),
|
||||||
state=dict(default='present', choices=['present', 'absent']),
|
state=dict(default='present', choices=['present', 'absent']),
|
||||||
|
@ -306,6 +317,7 @@ def main():
|
||||||
domain = module.params.get('domain')
|
domain = module.params.get('domain')
|
||||||
loadbalancer = module.params.get('loadbalancer')
|
loadbalancer = module.params.get('loadbalancer')
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
|
overwrite = module.params.get('overwrite')
|
||||||
priority = module.params.get('priority')
|
priority = module.params.get('priority')
|
||||||
server = module.params.get('server')
|
server = module.params.get('server')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
@ -323,8 +335,8 @@ def main():
|
||||||
state=state, ttl=ttl)
|
state=state, ttl=ttl)
|
||||||
else:
|
else:
|
||||||
rax_dns_record(module, comment=comment, data=data, domain=domain,
|
rax_dns_record(module, comment=comment, data=data, domain=domain,
|
||||||
name=name, priority=priority, record_type=record_type,
|
name=name, overwrite=overwrite, priority=priority,
|
||||||
state=state, ttl=ttl)
|
record_type=record_type, state=state, ttl=ttl)
|
||||||
|
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
|
|
Loading…
Reference in a new issue