diff --git a/changelogs/fragments/428-fix-kubeconfig-parameter-with-multiple-config-files.yaml b/changelogs/fragments/428-fix-kubeconfig-parameter-with-multiple-config-files.yaml new file mode 100644 index 0000000000..59a080c187 --- /dev/null +++ b/changelogs/fragments/428-fix-kubeconfig-parameter-with-multiple-config-files.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix kubeconfig parameter when multiple config files are provided (https://github.com/ansible-collections/kubernetes.core/issues/435). diff --git a/plugins/action/k8s_info.py b/plugins/action/k8s_info.py index cfcbb28d14..51a2bffaae 100644 --- a/plugins/action/k8s_info.py +++ b/plugins/action/k8s_info.py @@ -11,6 +11,7 @@ import traceback import os from contextlib import contextmanager +import platform from ansible.config.manager import ensure_type from ansible.errors import ( @@ -50,6 +51,9 @@ def output(self): return [self.remove_omit(d) for d in self.data] +ENV_KUBECONFIG_PATH_SEPARATOR = ";" if platform.system() == "Windows" else ":" + + class ActionModule(ActionBase): TRANSFERS_FILES = True @@ -308,11 +312,15 @@ def get_kubeconfig(self, kubeconfig, remote_transport, new_module_args): if not remote_transport: # kubeconfig is local # find in expected paths - kubeconfig = self._find_needle("files", kubeconfig) - - # decrypt kubeconfig found - actual_file = self._loader.get_real_file(kubeconfig, decrypt=True) - new_module_args["kubeconfig"] = actual_file + configs = [] + for config in kubeconfig.split(ENV_KUBECONFIG_PATH_SEPARATOR): + config = self._find_needle("files", config) + + # decrypt kubeconfig found + configs.append(self._loader.get_real_file(config, decrypt=True)) + new_module_args["kubeconfig"] = ENV_KUBECONFIG_PATH_SEPARATOR.join( + configs + ) elif isinstance(kubeconfig, dict): new_module_args["kubeconfig"] = kubeconfig diff --git a/plugins/doc_fragments/k8s_auth_options.py b/plugins/doc_fragments/k8s_auth_options.py index 90619dcca7..516ef64fda 100644 --- a/plugins/doc_fragments/k8s_auth_options.py +++ b/plugins/doc_fragments/k8s_auth_options.py @@ -28,6 +28,7 @@ class ModuleDocFragment(object): options are provided, the Kubernetes client will attempt to load the default configuration file from I(~/.kube/config). Can also be specified via K8S_AUTH_KUBECONFIG environment variable. + - Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms. - The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0. type: raw context: