From a5c8e952e8dbea9c9b5140e0b1c8680b2a1cdbf7 Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Tue, 6 Nov 2018 14:43:55 +0100 Subject: [PATCH] k8s_facts: fix handling of unknown resource types (#47857) --- changelogs/fragments/k8s_facts_fix.yaml | 1 + lib/ansible/module_utils/k8s/common.py | 2 ++ 2 files changed, 3 insertions(+) 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,