diff --git a/changelogs/fragments/51495-k8s-load-envvars.yaml b/changelogs/fragments/51495-k8s-load-envvars.yaml new file mode 100644 index 00000000000..f23c6a06a81 --- /dev/null +++ b/changelogs/fragments/51495-k8s-load-envvars.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- All K8S_AUTH_* environment variables are now properly loaded by the k8s lookup plugin diff --git a/lib/ansible/module_utils/k8s/common.py b/lib/ansible/module_utils/k8s/common.py index 1488fc211bb..a83885b8904 100644 --- a/lib/ansible/module_utils/k8s/common.py +++ b/lib/ansible/module_utils/k8s/common.py @@ -138,11 +138,11 @@ class K8sAnsibleMixin(object): auth = copy.deepcopy(auth_params) # If authorization variables aren't defined, look for them in environment variables - for key, value in iteritems(auth_params): - if key in auth_args and value is None: - env_value = os.getenv('K8S_AUTH_{0}'.format(key.upper()), None) + for arg in auth_args: + if auth_params.get(arg) is None: + env_value = os.getenv('K8S_AUTH_{0}'.format(arg.upper()), None) if env_value is not None: - auth[key] = env_value + auth[arg] = env_value def auth_set(*names): return all([auth.get(name) for name in names])