From ebaa17f59ffbdf79d7cc9bdbe20deb80332c6d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orosz=20D=C3=A1vid?= Date: Mon, 25 Jan 2021 13:00:13 +0100 Subject: [PATCH] dnsmadeeasy: Fix HTTP 400 errors when creating a TXT record (#1654) * dnsmadeeasy: Fix HTTP 400 errors when creating a TXT record * When creating a record the module fails on monitor API call * TXT records are surrounded by quotes in the API response Fixes: #1237 * dnsmadeeasy: Add changelog fragment * dnsmadeeasy: Fix pylint error * Update changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml Co-authored-by: Felix Fontein * Update plugins/modules/net_tools/dnsmadeeasy.py The dictionary might be empty Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../fragments/1654-dnsmadeeasy-http-400-fixes.yaml | 2 ++ plugins/modules/net_tools/dnsmadeeasy.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml diff --git a/changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml b/changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml new file mode 100644 index 0000000000..1934228644 --- /dev/null +++ b/changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml @@ -0,0 +1,2 @@ +bugfixes: + - dnsmadeeasy - fix HTTP 400 errors when creating a TXT record (https://github.com/ansible-collections/community.general/issues/1237). diff --git a/plugins/modules/net_tools/dnsmadeeasy.py b/plugins/modules/net_tools/dnsmadeeasy.py index 7d7c78fec6..c6bc70324c 100644 --- a/plugins/modules/net_tools/dnsmadeeasy.py +++ b/plugins/modules/net_tools/dnsmadeeasy.py @@ -467,6 +467,9 @@ class DME2(object): for result in self.all_records: if record_type == "MX": value = record_value.split(" ")[1] + # Note that TXT records are surrounded by quotes in the API response. + elif record_type == "TXT": + value = '"{0}"'.format(record_value) elif record_type == "SRV": value = record_value.split(" ")[3] else: @@ -651,7 +654,9 @@ def main(): record_changed = False if current_record: for i in new_record: - if str(current_record[i]) != str(new_record[i]): + # Remove leading and trailing quote character from values because TXT records + # are surrounded by quotes. + if str(current_record[i]).strip('"') != str(new_record[i]): record_changed = True new_record['id'] = str(current_record['id']) @@ -673,8 +678,11 @@ def main(): # create record and monitor as the record does not exist if not current_record: record = DME.createRecord(DME.prepareRecord(new_record)) - monitor = DME.updateMonitor(record['id'], DME.prepareMonitor(new_monitor)) - module.exit_json(changed=True, result=dict(record=record, monitor=monitor)) + if new_monitor.get('monitor') and record_type == "A": + monitor = DME.updateMonitor(record['id'], DME.prepareMonitor(new_monitor)) + module.exit_json(changed=True, result=dict(record=record, monitor=monitor)) + else: + module.exit_json(changed=True, result=dict(record=record, monitor=current_monitor)) # update the record updated = False