From b842b1b97ef3c8597d0fb2e9c0b118c638fc0cdb Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 29 Nov 2018 09:00:39 +0100 Subject: [PATCH] ACME: improve error handling (#49266) * Improve error handling: when parse_json_result is False, still return the error message. * Remove content body from info dict. * Add changelog. --- changelogs/fragments/49266-acme-error-messages.yml | 2 ++ lib/ansible/module_utils/acme.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/49266-acme-error-messages.yml diff --git a/changelogs/fragments/49266-acme-error-messages.yml b/changelogs/fragments/49266-acme-error-messages.yml new file mode 100644 index 00000000000..911af940aef --- /dev/null +++ b/changelogs/fragments/49266-acme-error-messages.yml @@ -0,0 +1,2 @@ +bugfixes: +- "ACME modules: improve error messages in some cases (include error returned by server)." diff --git a/lib/ansible/module_utils/acme.py b/lib/ansible/module_utils/acme.py index 8e917f8a09b..3e776fa1693 100644 --- a/lib/ansible/module_utils/acme.py +++ b/lib/ansible/module_utils/acme.py @@ -564,7 +564,7 @@ class ACMEAccount(object): try: content = resp.read() except AttributeError: - content = info.get('body') + content = info.pop('body') if content or not parse_json_result: if (parse_json_result and info['content-type'].startswith('application/json')) or 400 <= info['status'] < 600: @@ -579,6 +579,8 @@ class ACMEAccount(object): continue if parse_json_result: result = decoded_result + else: + result = content except ValueError: raise ModuleFailException("Failed to parse the ACME response: {0} {1}".format(url, content)) else: @@ -608,7 +610,7 @@ class ACMEAccount(object): try: content = resp.read() except AttributeError: - content = info.get('body') + content = info.pop('body') # Process result if parse_json_result: