Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Handle set object retrieved from lookup plugin #118

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions molecule/default/tasks/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@
metadata:
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
k8s_info:
kind: Namespace
Expand Down
6 changes: 4 additions & 2 deletions plugins/lookup/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@
type: complex
"""

from ansible.errors import AnsibleError
from ansible.module_utils.common._collections_compat import KeysView
from ansible.plugins.lookup import LookupBase

from ansible_collections.community.kubernetes.plugins.module_utils.common import K8sAnsibleMixin

from ansible.errors import AnsibleError


try:
from openshift.dynamic import DynamicClient
Expand Down Expand Up @@ -253,6 +253,8 @@ def run(self, terms, variables=None, **kwargs):
if cluster_info == 'version':
return [self.client.version]
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]

self.kind = kwargs.get('kind')
Expand Down