From b35ac8080f1749d341212be40615d591adc57ff9 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Wed, 29 Aug 2018 21:04:04 +1000 Subject: [PATCH] Change the return key of k8s_facts (#44446) `items` is a *terrible* return key for ansible as Jinja will often think it refers to the `items()` function. Even though you can typically work around this with `results['items']`, sometimes even that doesn't work: ``` - name: Resources should exist assert: that: item.status.phase == 'Active' loop: "{{ k8s_namespaces['items'] }}" ``` ``` fatal: [testhost]: FAILED! => {"msg": "Invalid data passed to 'loop', it requires a list, got this instead: . Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."} ``` Change it now while we still can. --- lib/ansible/module_utils/k8s/common.py | 4 ++-- lib/ansible/modules/clustering/k8s/k8s_facts.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/k8s/common.py b/lib/ansible/module_utils/k8s/common.py index 95839daabf..3788a4e2a9 100644 --- a/lib/ansible/module_utils/k8s/common.py +++ b/lib/ansible/module_utils/k8s/common.py @@ -214,9 +214,9 @@ class K8sAnsibleMixin(object): return dict(items=[]) if 'items' in result: - return result + return dict(resources=result['items']) else: - return dict(items=[result]) + return dict(resources=[result]) def remove_aliases(self): """ diff --git a/lib/ansible/modules/clustering/k8s/k8s_facts.py b/lib/ansible/modules/clustering/k8s/k8s_facts.py index 8586e25946..974135168d 100644 --- a/lib/ansible/modules/clustering/k8s/k8s_facts.py +++ b/lib/ansible/modules/clustering/k8s/k8s_facts.py @@ -101,7 +101,7 @@ EXAMPLES = ''' ''' RETURN = ''' -items: +resources: description: - The object(s) that exists returned: success