Skip to content

Commit 6301760

Browse files
committed
common: Handle aliases correctly
Fixed get_api_client API to handle `aliases` that are passed via inventory configuration or module parameters. Signed-off-by: Abhijeet Kasurde <[email protected]>
1 parent b68bf7c commit 6301760

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- common - handle ``aliases`` passed from inventory or module params.

molecule/default/tasks/full.yml

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
debug:
1111
var: output
1212

13+
- name: Use aliases and check if those values are picked up
14+
k8s:
15+
name: testing
16+
kind: Namespace
17+
validate_certs: yes
18+
ssl_ca_cert: /dev/null # invalid CA certificate
19+
ignore_errors: yes
20+
register: output
21+
22+
- name: assert that ssl_ca_cert caused a failure (and therefore was correctly translated to ssl_ca_cert)
23+
assert:
24+
that:
25+
- output is failed
26+
1327
- name: Setting validate_certs to true causes a failure
1428
k8s:
1529
name: testing

plugins/module_utils/common.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,15 @@ def _raise_or_fail(exc, msg):
129129

130130
# If authorization variables aren't defined, look for them in environment variables
131131
for true_name, arg_name in AUTH_ARG_MAP.items():
132-
if module and module.params.get(arg_name):
133-
auth[true_name] = module.params.get(arg_name)
132+
if module:
133+
if arg_name in module.params and module.params.get(arg_name) is not None:
134+
auth[true_name] = module.params.get(arg_name)
135+
elif true_name in module.params and module.params.get(true_name) is not None:
136+
# Aliases
137+
auth[true_name] = module.params.get(true_name)
138+
elif true_name in kwargs and kwargs.get(true_name) is not None:
139+
# Aliases
140+
auth[true_name] = kwargs.get(true_name)
134141
elif arg_name in kwargs and kwargs.get(arg_name) is not None:
135142
auth[true_name] = kwargs.get(arg_name)
136143
else:

tests/integration/targets/kubernetes/tasks/validate_not_installed.yml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
ignore_errors: yes
1919
register: k8s_no_validate
2020

21+
- name: Debug register value
22+
debug:
23+
msg: "{{ k8s_no_validate }}"
24+
2125
- name: assert that k8s_no_validate fails gracefully
2226
assert:
2327
that:

0 commit comments

Comments
 (0)