parent
3ab9030f05
commit
ec20d4b13e
1 changed files with 18 additions and 5 deletions
|
@ -59,10 +59,11 @@ options:
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- DNS record will be modified on this C(zone).
|
- DNS record will be modified on this C(zone).
|
||||||
required: true
|
- When omitted DNS will be queried to attempt finding the correct zone.
|
||||||
|
- Starting with Ansible 2.7 this parameter is optional.
|
||||||
record:
|
record:
|
||||||
description:
|
description:
|
||||||
- Sets the DNS record to modify.
|
- Sets the DNS record to modify. When zone is omitted this has to be absolute (ending with a dot).
|
||||||
required: true
|
required: true
|
||||||
type:
|
type:
|
||||||
description:
|
description:
|
||||||
|
@ -172,11 +173,23 @@ class RecordManager(object):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
|
|
||||||
if module.params['zone'][-1] != '.':
|
if module.params['zone'] is None:
|
||||||
self.zone = module.params['zone'] + '.'
|
if module.params['record'][-1] != '.':
|
||||||
|
self.module.fail_json(msg='record must be absolute when omitting zone parameter')
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.zone = dns.resolver.zone_for_name(self.module.params['record']).to_text()
|
||||||
|
except (dns.exception.Timeout, dns.resolver.NoNameservers, dns.resolver.NoRootSOA) as e:
|
||||||
|
self.module.fail_json(msg='Zone resolver error (%s): %s' % (e.__class__.__name__, to_native(e)))
|
||||||
|
|
||||||
|
if self.zone is None:
|
||||||
|
self.module.fail_json(msg='Unable to find zone, dnspython returned None')
|
||||||
else:
|
else:
|
||||||
self.zone = module.params['zone']
|
self.zone = module.params['zone']
|
||||||
|
|
||||||
|
if self.zone[-1] != '.':
|
||||||
|
self.zone += '.'
|
||||||
|
|
||||||
if module.params['key_name']:
|
if module.params['key_name']:
|
||||||
try:
|
try:
|
||||||
self.keyring = dns.tsigkeyring.from_text({
|
self.keyring = dns.tsigkeyring.from_text({
|
||||||
|
@ -332,7 +345,7 @@ def main():
|
||||||
key_name=dict(required=False, type='str'),
|
key_name=dict(required=False, type='str'),
|
||||||
key_secret=dict(required=False, type='str', no_log=True),
|
key_secret=dict(required=False, type='str', no_log=True),
|
||||||
key_algorithm=dict(required=False, default='hmac-md5', choices=tsig_algs, type='str'),
|
key_algorithm=dict(required=False, default='hmac-md5', choices=tsig_algs, type='str'),
|
||||||
zone=dict(required=True, type='str'),
|
zone=dict(required=False, default=None, type='str'),
|
||||||
record=dict(required=True, type='str'),
|
record=dict(required=True, type='str'),
|
||||||
type=dict(required=False, default='A', type='str'),
|
type=dict(required=False, default='A', type='str'),
|
||||||
ttl=dict(required=False, default=3600, type='int'),
|
ttl=dict(required=False, default=3600, type='int'),
|
||||||
|
|
Loading…
Reference in a new issue