Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions awx_collection/plugins/doc_fragments/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class ModuleDocFragment(object):
- If provided, the other locations for config files will not be considered.
type: path
aliases: [tower_config_file]
http_headers:
description:
- Arbitrary headers to add to every HTTP request
type: dict

notes:
- If no I(config_file) is provided we will attempt to use the tower-cli library
Expand Down
14 changes: 10 additions & 4 deletions awx_collection/plugins/module_utils/controller_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ControllerModule(AnsibleModule):
validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['CONTROLLER_VERIFY_SSL', 'TOWER_VERIFY_SSL'])),
request_timeout=dict(type='float', required=False, fallback=(env_fallback, ['CONTROLLER_REQUEST_TIMEOUT'])),
controller_config_file=dict(type='path', aliases=['tower_config_file'], required=False, default=None),
http_headers=dict(type='dict', required=False, default={}),
)
# Associations of these types are ordered and have special consideration in the modified associations function
ordered_associations = ['instance_groups', 'galaxy_credentials', 'input_inventories']
Expand Down Expand Up @@ -473,6 +474,8 @@ def make_request(self, method, endpoint, *args, **kwargs):

# Extract the headers, this will be used in a couple of places
headers = kwargs.get('headers', {})
if self.params.get('http_headers'):
headers.update(self.params['http_headers'])

# Authenticate to AWX (if not already done so)
if not self.authenticated:
Expand Down Expand Up @@ -626,16 +629,19 @@ def _authenticate_with_basic_auth(self):
if self.username and self.password:
# use api url /api/v2/me to get current user info as a testing request
me_url = self.build_url("me").geturl()
headers={
"Content-Type": "application/json",
"Authorization": self._get_basic_authorization_header(),
}
if self.params.get('http_headers'):
headers.update(self.params['http_headers'])
self.session.open(
"GET",
me_url,
validate_certs=self.verify_ssl,
timeout=self.request_timeout,
follow_redirects=True,
headers={
"Content-Type": "application/json",
"Authorization": self._get_basic_authorization_header(),
},
headers=headers,
)

def authenticate(self, **kwargs):
Expand Down