From 03eccdea19c61d7f9abcc1498307d83f969a614c Mon Sep 17 00:00:00 2001 From: Gaudenz Steinlin Date: Mon, 18 Dec 2017 14:49:33 +0100 Subject: [PATCH] Send API parameters as JSON in cloudscale_server module Use JSON to send the POST data to the API instead of an urlencoded string. Urlencoding is not really a good match for some Python datatypes. This fixes an issue when submitting a list of SSH keys which did not get translated properly. Partial cherry-pick of the important parts of 4c94c6f9ba. --- lib/ansible/modules/cloud/cloudscale/cloudscale_server.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py index 8abea6784d6..f39a6340795 100644 --- a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py +++ b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py @@ -217,7 +217,6 @@ from datetime import datetime, timedelta from time import sleep from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.urls import fetch_url @@ -273,12 +272,14 @@ class AnsibleCloudscaleServer(object): def _post(self, api_call, data=None): + headers = self._auth_header.copy() if data is not None: - data = urlencode(data) + data = self._module.jsonify(data) + headers['Content-type'] = 'application/json' resp, info = fetch_url(self._module, API_URL+api_call, - headers = self._auth_header, + headers = headers, method='POST', data=data)