mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 21:42:38 +00:00
Handle set object retrieved from lookup plugin (#118)
api_groups is returned as "dict_keys()" which k8s lookip plugin does not handle. Typecasting with list make it available to default callback plugin.
This commit is contained in:
@@ -185,6 +185,13 @@
|
|||||||
metadata:
|
metadata:
|
||||||
name: testing1
|
name: testing1
|
||||||
|
|
||||||
|
### https://github.com/ansible-collections/community.kubernetes/issues/111
|
||||||
|
- set_fact:
|
||||||
|
api_groups: "{{ lookup('k8s', cluster_info='api_groups') }}"
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: api_groups
|
||||||
|
|
||||||
- name: Namespace should exist
|
- name: Namespace should exist
|
||||||
k8s_info:
|
k8s_info:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
|
|||||||
@@ -194,12 +194,12 @@ RETURN = """
|
|||||||
type: complex
|
type: complex
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
|
from ansible.module_utils.common._collections_compat import KeysView
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
|
||||||
from ansible_collections.community.kubernetes.plugins.module_utils.common import K8sAnsibleMixin
|
from ansible_collections.community.kubernetes.plugins.module_utils.common import K8sAnsibleMixin
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openshift.dynamic import DynamicClient
|
from openshift.dynamic import DynamicClient
|
||||||
@@ -253,6 +253,8 @@ class KubernetesLookup(K8sAnsibleMixin):
|
|||||||
if cluster_info == 'version':
|
if cluster_info == 'version':
|
||||||
return [self.client.version]
|
return [self.client.version]
|
||||||
if cluster_info == 'api_groups':
|
if cluster_info == 'api_groups':
|
||||||
|
if isinstance(self.client.resources.api_groups, KeysView):
|
||||||
|
return [list(self.client.resources.api_groups)]
|
||||||
return [self.client.resources.api_groups]
|
return [self.client.resources.api_groups]
|
||||||
|
|
||||||
self.kind = kwargs.get('kind')
|
self.kind = kwargs.get('kind')
|
||||||
|
|||||||
Reference in New Issue
Block a user