Adds overwrite option to rax_dns_record

This commit is contained in:
bobgroves 2015-04-12 16:38:29 -04:00
parent fcea4e1884
commit b3066fcff7

View file

@ -44,6 +44,12 @@ options:
description:
- FQDN record name to create
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:
description:
- 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,
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"""
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)
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:
module.fail_json(msg='%s' % e.message)
module.fail_json(msg='overwrite=true and there are multiple matching records')
except pyrax.exceptions.DomainRecordNotFound, e:
try:
record_data = {
@ -278,6 +288,7 @@ def main():
domain=dict(),
loadbalancer=dict(),
name=dict(required=True),
overwrite=dict(type='bool', default=True),
priority=dict(type='int'),
server=dict(),
state=dict(default='present', choices=['present', 'absent']),
@ -306,6 +317,7 @@ def main():
domain = module.params.get('domain')
loadbalancer = module.params.get('loadbalancer')
name = module.params.get('name')
overwrite = module.params.get('overwrite')
priority = module.params.get('priority')
server = module.params.get('server')
state = module.params.get('state')
@ -323,8 +335,8 @@ def main():
state=state, ttl=ttl)
else:
rax_dns_record(module, comment=comment, data=data, domain=domain,
name=name, priority=priority, record_type=record_type,
state=state, ttl=ttl)
name=name, overwrite=overwrite, priority=priority,
record_type=record_type, state=state, ttl=ttl)
# import module snippets