diff --git a/lib/ansible/module_utils/scaleway.py b/lib/ansible/module_utils/scaleway.py index 762ceed806..caf6886f26 100644 --- a/lib/ansible/module_utils/scaleway.py +++ b/lib/ansible/module_utils/scaleway.py @@ -1,4 +1,5 @@ import json +import sys from ansible.module_utils.urls import fetch_url @@ -33,9 +34,12 @@ class Response(object): class ScalewayAPI(object): - def __init__(self, module, headers, base_url): + def __init__(self, module, base_url, headers=None): self.module = module - self.headers = headers + self.headers = {'User-Agent': self.get_user_agent_string(module), + 'Content-type': 'application/json'} + if headers is not None: + self.headers.update(headers) self.base_url = base_url def _url_builder(self, path): @@ -59,6 +63,10 @@ class ScalewayAPI(object): return Response(resp, info) + @staticmethod + def get_user_agent_string(module): + return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0]) + def get(self, path, data=None, headers=None): return self.send('GET', path, data, headers) diff --git a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py index 09ac2fb263..4b1348abd6 100644 --- a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py +++ b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py @@ -584,8 +584,7 @@ def core(module): } compute_api = ScalewayAPI(module=module, - headers={'X-Auth-Token': api_token, - 'Content-type': 'application/json'}, + headers={'X-Auth-Token': api_token}, base_url=SCALEWAY_LOCATION[region]["api_endpoint"]) changed, summary = state_strategy[wished_server["state"]](compute_api=compute_api, wished_server=wished_server) diff --git a/lib/ansible/modules/cloud/scaleway/scaleway_sshkey.py b/lib/ansible/modules/cloud/scaleway/scaleway_sshkey.py index c8070fd0b4..d47b350107 100644 --- a/lib/ansible/modules/cloud/scaleway/scaleway_sshkey.py +++ b/lib/ansible/modules/cloud/scaleway/scaleway_sshkey.py @@ -109,8 +109,7 @@ def core(module): ssh_pub_key = module.params['ssh_pub_key'] state = module.params["state"] account_api = ScalewayAPI(module, - headers={'X-Auth-Token': api_token, - 'Content-type': 'application/json'}, + headers={'X-Auth-Token': api_token}, base_url=module.params["base_url"]) response = account_api.get('organizations')