diff --git a/lib/ansible/modules/monitoring/grafana_dashboard.py b/lib/ansible/modules/monitoring/grafana_dashboard.py index e351204693c..74cf592dbad 100644 --- a/lib/ansible/modules/monitoring/grafana_dashboard.py +++ b/lib/ansible/modules/monitoring/grafana_dashboard.py @@ -107,11 +107,12 @@ slug: sample: foo ''' -import base64 import json -import os +import base64 + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_bytes __metaclass__ = type @@ -166,7 +167,7 @@ def grafana_create_dashboard(module, data): if 'grafana_api_key' in data and data['grafana_api_key']: headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] else: - auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '')) headers['Authorization'] = 'Basic %s' % auth grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) @@ -224,7 +225,7 @@ def grafana_delete_dashboard(module, data): if 'grafana_api_key' in data and data['grafana_api_key']: headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] else: - auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '')) headers['Authorization'] = 'Basic %s' % auth grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) @@ -257,7 +258,7 @@ def grafana_export_dashboard(module, data): if 'grafana_api_key' in data and data['grafana_api_key']: headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] else: - auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '')) headers['Authorization'] = 'Basic %s' % auth grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) diff --git a/lib/ansible/modules/monitoring/grafana_datasource.py b/lib/ansible/modules/monitoring/grafana_datasource.py index 3e8acde8576..e5f1f59bcf2 100644 --- a/lib/ansible/modules/monitoring/grafana_datasource.py +++ b/lib/ansible/modules/monitoring/grafana_datasource.py @@ -243,11 +243,12 @@ after: "withCredentials": false } ''' -import base64 import json -import os +import base64 + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_bytes __metaclass__ = type @@ -349,7 +350,7 @@ def grafana_create_datasource(module, data): if 'grafana_api_key' in data and data['grafana_api_key'] is not None: headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] else: - auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '')) headers['Authorization'] = 'Basic %s' % auth grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) @@ -409,7 +410,7 @@ def grafana_delete_datasource(module, data): if 'grafana_api_key' in data and data['grafana_api_key']: headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] else: - auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '')) headers['Authorization'] = 'Basic %s' % auth grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) diff --git a/lib/ansible/modules/monitoring/pagerduty.py b/lib/ansible/modules/monitoring/pagerduty.py index 7d9f57af034..14c15d76ae1 100644 --- a/lib/ansible/modules/monitoring/pagerduty.py +++ b/lib/ansible/modules/monitoring/pagerduty.py @@ -164,19 +164,20 @@ EXAMPLES = ''' service: '{{ pd_window.result.maintenance_window.id }}' ''' -import base64 import datetime import json +import base64 from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_bytes def auth_header(user, passwd, token): if token: return "Token token=%s" % token - auth = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (user, passwd)).replace('\n', '')) return "Basic %s" % auth diff --git a/lib/ansible/modules/network/citrix/_netscaler.py b/lib/ansible/modules/network/citrix/_netscaler.py index b8bf36bf347..e5347ce51af 100644 --- a/lib/ansible/modules/network/citrix/_netscaler.py +++ b/lib/ansible/modules/network/citrix/_netscaler.py @@ -88,14 +88,14 @@ EXAMPLES = ''' action: disable ''' -import base64 import json import socket import traceback +import base64 from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_native, to_bytes from ansible.module_utils.urls import fetch_url @@ -115,7 +115,7 @@ class netscaler(object): if not len(data_json): data_json = None - auth = base64.encodestring('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip() + auth = base64.b64encode(to_bytes('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip()) headers = { 'Authorization': 'Basic %s' % auth, 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/lib/ansible/modules/source_control/github_hooks.py b/lib/ansible/modules/source_control/github_hooks.py index ef5c19be1ab..e1480f668e1 100644 --- a/lib/ansible/modules/source_control/github_hooks.py +++ b/lib/ansible/modules/source_control/github_hooks.py @@ -80,15 +80,16 @@ EXAMPLES = ''' delegate_to: localhost ''' -import base64 import json +import base64 from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_bytes def request(module, url, user, oauthkey, data='', method='GET'): - auth = base64.encodestring('%s:%s' % (user, oauthkey)).replace('\n', '') + auth = base64.b64encode(to_bytes('%s:%s' % (user, oauthkey)).replace('\n', '')) headers = { 'Authorization': 'Basic %s' % auth, }