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:
parent
ac6205b9e8
commit
e462e3bb3f
1 changed files with 41 additions and 23 deletions
|
@ -84,6 +84,15 @@ EXAMPLES = '''
|
||||||
record: "ansible"
|
record: "ansible"
|
||||||
value: "192.168.1.1"
|
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
|
- name: Remove puppet.example.org CNAME
|
||||||
nsupdate:
|
nsupdate:
|
||||||
key_name: "nsupdate"
|
key_name: "nsupdate"
|
||||||
|
@ -116,9 +125,9 @@ type:
|
||||||
type: string
|
type: string
|
||||||
sample: 'CNAME'
|
sample: 'CNAME'
|
||||||
value:
|
value:
|
||||||
description: DNS record value
|
description: DNS record value(s)
|
||||||
returned: success
|
returned: success
|
||||||
type: string
|
type: list
|
||||||
sample: '192.168.1.1'
|
sample: '192.168.1.1'
|
||||||
zone:
|
zone:
|
||||||
description: DNS record zone
|
description: DNS record zone
|
||||||
|
@ -223,27 +232,35 @@ class RecordManager(object):
|
||||||
|
|
||||||
def create_record(self):
|
def create_record(self):
|
||||||
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
|
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
|
||||||
try:
|
for entry in self.module.params['value']:
|
||||||
update.add(self.module.params['record'],
|
try:
|
||||||
self.module.params['ttl'],
|
update.add(self.module.params['record'],
|
||||||
self.module.params['type'],
|
self.module.params['ttl'],
|
||||||
self.module.params['value'])
|
self.module.params['type'],
|
||||||
except AttributeError:
|
entry)
|
||||||
self.module.fail_json(msg='value needed when state=present')
|
except AttributeError:
|
||||||
except dns.exception.SyntaxError:
|
self.module.fail_json(msg='value needed when state=present')
|
||||||
self.module.fail_json(msg='Invalid/malformed value')
|
except dns.exception.SyntaxError:
|
||||||
|
self.module.fail_json(msg='Invalid/malformed value')
|
||||||
|
|
||||||
response = self.__do_update(update)
|
response = self.__do_update(update)
|
||||||
return dns.message.Message.rcode(response)
|
return dns.message.Message.rcode(response)
|
||||||
|
|
||||||
def modify_record(self):
|
def modify_record(self):
|
||||||
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
|
update = dns.update.Update(self.zone, keyring=self.keyring, keyalgorithm=self.algorithm)
|
||||||
update.replace(self.module.params['record'],
|
update.delete(self.module.params['record'], self.module.params['type'])
|
||||||
self.module.params['ttl'],
|
for entry in self.module.params['value']:
|
||||||
self.module.params['type'],
|
try:
|
||||||
self.module.params['value'])
|
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)
|
response = self.__do_update(update)
|
||||||
|
|
||||||
return dns.message.Message.rcode(response)
|
return dns.message.Message.rcode(response)
|
||||||
|
|
||||||
def remove_record(self):
|
def remove_record(self):
|
||||||
|
@ -282,12 +299,13 @@ class RecordManager(object):
|
||||||
if self.dns_rc == 0:
|
if self.dns_rc == 0:
|
||||||
if self.module.params['state'] == 'absent':
|
if self.module.params['state'] == 'absent':
|
||||||
return 1
|
return 1
|
||||||
try:
|
for entry in self.module.params['value']:
|
||||||
update.present(self.module.params['record'], self.module.params['type'], self.module.params['value'])
|
try:
|
||||||
except AttributeError:
|
update.present(self.module.params['record'], self.module.params['type'], entry)
|
||||||
self.module.fail_json(msg='value needed when state=present')
|
except AttributeError:
|
||||||
except dns.exception.SyntaxError:
|
self.module.fail_json(msg='value needed when state=present')
|
||||||
self.module.fail_json(msg='Invalid/malformed value')
|
except dns.exception.SyntaxError:
|
||||||
|
self.module.fail_json(msg='Invalid/malformed value')
|
||||||
response = self.__do_update(update)
|
response = self.__do_update(update)
|
||||||
self.dns_rc = dns.message.Message.rcode(response)
|
self.dns_rc = dns.message.Message.rcode(response)
|
||||||
if self.dns_rc == 0:
|
if self.dns_rc == 0:
|
||||||
|
@ -313,7 +331,7 @@ def main():
|
||||||
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'),
|
||||||
value=dict(required=False, default=None, type='str')
|
value=dict(required=False, default=None, type='list')
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue