From 008313b8cc9d6e8ec7874a26390ed3decad6175a Mon Sep 17 00:00:00 2001 From: Hoshiyo Date: Tue, 19 Feb 2019 16:08:41 +0100 Subject: [PATCH] fix(rundeck_acl_policy): compatible python 2 and 3 (#52473) * fix(rundeck_acl_policy): compatible python 2 and 3 * Add changelog fragment * Use to_text instead of decode --- changelogs/fragments/rundeck-acl-policy-python-version.yaml | 3 +++ lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/rundeck-acl-policy-python-version.yaml diff --git a/changelogs/fragments/rundeck-acl-policy-python-version.yaml b/changelogs/fragments/rundeck-acl-policy-python-version.yaml new file mode 100644 index 00000000000..372f205211c --- /dev/null +++ b/changelogs/fragments/rundeck-acl-policy-python-version.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Allow to use rundeck_acl_policy with python 2 and 3 diff --git a/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py b/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py index ad855e13091..55bb4420001 100644 --- a/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py +++ b/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py @@ -102,6 +102,7 @@ after: # import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_text import json @@ -130,9 +131,9 @@ class RundeckACLManager: self.handle_http_code_if_needed(info) if resp is not None: resp = resp.read() - if resp != "": + if resp != b"": try: - json_resp = json.loads(resp) + json_resp = json.loads(to_text(resp, errors='surrogate_or_strict')) return json_resp, info except ValueError as e: self.module.fail_json(msg="Rundeck response was not a valid JSON. Exception was: %s. "