From 51bf373fd17eda443e187e002e4fb0d89f0414e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Thu, 8 Mar 2018 17:55:11 +0100 Subject: [PATCH] vultr: fix py3 compat (#37171) (#37195) * vr_server: fix base64 encoding with py3 * vultr: fix AttributeError with py3 (cherry picked from commit 4b6b2d4206ef9559ddbe56e6c770483e20763795) --- lib/ansible/module_utils/vultr.py | 10 ++++++++-- lib/ansible/modules/cloud/vultr/vr_server.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/vultr.py b/lib/ansible/module_utils/vultr.py index 7beb4fa3c71..69496f5c41c 100644 --- a/lib/ansible/module_utils/vultr.py +++ b/lib/ansible/module_utils/vultr.py @@ -139,10 +139,16 @@ class Vultr: for k, v in data.items(): if isinstance(v, list): for s in v: - data_list += '&%s[]=%s' % (k, urllib.quote(s)) + try: + data_list += '&%s[]=%s' % (k, urllib.quote(s)) + except AttributeError: + data_list += '&%s[]=%s' % (k, urllib.parse.quote(s)) elif v is not None: data_encoded[k] = v - data = urllib.urlencode(data_encoded) + data_list + try: + data = urllib.urlencode(data_encoded) + data_list + except AttributeError: + data = urllib.parse.urlencode(data_encoded) + data_list for s in range(0, self.api_config['api_retries']): response, info = fetch_url( diff --git a/lib/ansible/modules/cloud/vultr/vr_server.py b/lib/ansible/modules/cloud/vultr/vr_server.py index 7e0df4dd8b4..7ab89afdd85 100644 --- a/lib/ansible/modules/cloud/vultr/vr_server.py +++ b/lib/ansible/modules/cloud/vultr/vr_server.py @@ -320,6 +320,7 @@ vultr_server: import time import base64 from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.vultr import ( Vultr, vultr_argument_spec, @@ -415,7 +416,7 @@ class AnsibleVultrServer(Vultr): def get_user_data(self): user_data = self.module.params.get('user_data') if user_data is not None: - user_data = base64.b64encode(str(user_data)) + user_data = to_text(base64.b64encode(to_bytes(user_data))) return user_data def get_server_user_data(self, server):