digital_ocean_domain: fix to allow updating the module param ip between calls (#42009)

* update the domain record with the new ip from params if resource exists

* fixes for pylint and pep8 checks
This commit is contained in:
Tom Hodder 2018-09-22 08:13:20 +01:00 committed by ansibot
parent 905acd7c9e
commit c123b4e7ef

View file

@ -134,10 +134,22 @@ class DoManager(DigitalOceanHelper, object):
else: else:
return json return json
def edit_domain_record(self): def edit_domain_record(self, record):
params = {'name': self.domain_name} params = {'name': '@',
resp = self.put('domains/%s/records/%s' % (self.domain_name, self.domain_id), data=params) 'data': self.module.params.get('ip')}
resp = self.put('domains/%s/records/%s' % (self.domain_name, record['id']), data=params)
status, json = self.jsonify(resp) status, json = self.jsonify(resp)
return json['domain_record']
def create_domain_record(self):
params = {'name': '@',
'type': 'A',
'data': self.module.params.get('ip')}
resp = self.post('domains/%s/records' % (self.domain_name), data=params)
status, json = self.jsonify(resp)
return json['domain_record'] return json['domain_record']
@ -160,8 +172,11 @@ def core(module):
if record['name'] == "@" and record['type'] == 'A': if record['name'] == "@" and record['type'] == 'A':
at_record = record at_record = record
if not at_record['data'] == module.params.get('ip'): if not at_record:
do_manager.edit_domain_record() do_manager.create_domain_record()
module.exit_json(changed=True, domain=do_manager.find())
elif not at_record['data'] == module.params.get('ip'):
do_manager.edit_domain_record(at_record)
module.exit_json(changed=True, domain=do_manager.find()) module.exit_json(changed=True, domain=do_manager.find())
else: else:
module.exit_json(changed=False, domain=do_manager.domain_record()) module.exit_json(changed=False, domain=do_manager.domain_record())