diff --git a/changelogs/fragments/k8s_facts_fix.yaml b/changelogs/fragments/k8s_facts_fix.yaml index bfef56a34e..796c083a45 100644 --- a/changelogs/fragments/k8s_facts_fix.yaml +++ b/changelogs/fragments/k8s_facts_fix.yaml @@ -1,3 +1,4 @@ --- bugfixes: - k8s_facts now returns a resources key in all situations +- "k8s_facts: fix handling of unknown resource types" diff --git a/lib/ansible/module_utils/k8s/common.py b/lib/ansible/module_utils/k8s/common.py index caecdecdb6..b285469f56 100644 --- a/lib/ansible/module_utils/k8s/common.py +++ b/lib/ansible/module_utils/k8s/common.py @@ -183,6 +183,8 @@ class K8sAnsibleMixin(object): def kubernetes_facts(self, kind, api_version, name=None, namespace=None, label_selectors=None, field_selectors=None): resource = self.find_resource(kind, api_version) + if not resource: + return dict(resources=[]) try: result = resource.get(name=name, namespace=namespace,