1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Support one to many A records in nsupdate module (#25620)

* Updating the nsupdate module to accept a list for 'value' instead
of a string. This is to allow manipulating 1:many DNS records.

A string can still be supplied so it should be backwards compatible.

Addresses issue #25554

* Update nsupdate.py

* Update nsupdate.py

* Update nsupdate.py
This commit is contained in:
David Critch 2017-09-13 18:21:48 -04:00 committed by ansibot
parent ac6205b9e8
commit e462e3bb3f

View file

@ -84,6 +84,15 @@ EXAMPLES = '''
record: "ansible"
value: "192.168.1.1"
- name: Add or modify ansible.example.org A to 192.168.1.1, 192.168.1.2 and 192.168.1.3"
nsupdate:
key_name: "nsupdate"
key_secret: "+bFQtBCta7j2vWkjPkAFtgA=="
server: "10.1.1.1"
zone: "example.org"
record: "ansible"
value: ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
- name: Remove puppet.example.org CNAME
nsupdate:
key_name: "nsupdate"
@ -116,9 +125,9 @@ type:
type: string
sample: 'CNAME'
value:
description: DNS record value
description: DNS record value(s)
returned: success
type: string
type: list
sample: '192.168.1.1'
zone:
description: DNS record zone
@ -223,27 +232,35 @@ class RecordManager(object):
def create_record(self):
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
try:
update.add(self.module.params['record'],
self.module.params['ttl'],
self.module.params['type'],
self.module.params['value'])
except AttributeError:
self.module.fail_json(msg='value needed when state=present')
except dns.exception.SyntaxError:
self.module.fail_json(msg='Invalid/malformed value')
for entry in self.module.params['value']:
try:
update.add(self.module.params['record'],
self.module.params['ttl'],
self.module.params['type'],
entry)
except AttributeError:
self.module.fail_json(msg='value needed when state=present')
except dns.exception.SyntaxError:
self.module.fail_json(msg='Invalid/malformed value')
response = self.__do_update(update)
return dns.message.Message.rcode(response)
def modify_record(self):
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
update.replace(self.module.params['record'],
self.module.params['ttl'],
self.module.params['type'],
self.module.params['value'])
update.delete(self.module.params['record'], self.module.params['type'])
for entry in self.module.params['value']:
try:
update.add(self.module.params['record'],
self.module.params['ttl'],
self.module.params['type'],
entry)
except AttributeError:
self.module.fail_json(msg='value needed when state=present')
except dns.exception.SyntaxError:
self.module.fail_json(msg='Invalid/malformed value')
response = self.__do_update(update)
return dns.message.Message.rcode(response)
def remove_record(self):
@ -282,12 +299,13 @@ class RecordManager(object):
if self.dns_rc == 0:
if self.module.params['state'] == 'absent':
return 1
try:
update.present(self.module.params['record'], self.module.params['type'], self.module.params['value'])
except AttributeError:
self.module.fail_json(msg='value needed when state=present')
except dns.exception.SyntaxError:
self.module.fail_json(msg='Invalid/malformed value')
for entry in self.module.params['value']:
try:
update.present(self.module.params['record'], self.module.params['type'], entry)
except AttributeError:
self.module.fail_json(msg='value needed when state=present')
except dns.exception.SyntaxError:
self.module.fail_json(msg='Invalid/malformed value')
response = self.__do_update(update)
self.dns_rc = dns.message.Message.rcode(response)
if self.dns_rc == 0:
@ -313,7 +331,7 @@ def main():
record=dict(required=True, type='str'),
type=dict(required=False, default='A', type='str'),
ttl=dict(required=False, default=3600, type='int'),
value=dict(required=False, default=None, type='str')
value=dict(required=False, default=None, type='list')
),
supports_check_mode=True
)