ansible-collections / community.kubernetes

Kubernetes Collection for Ansible
https://galaxy.ansible.com/community/kubernetes
GNU General Public License v3.0
265 stars 106 forks source link

lookup and module_defaults #335

Closed er1z closed 3 years ago

er1z commented 3 years ago

Don't know where to classify this issue. Is it possible to have following to be successful?

- name: k8s stuff
  module_defaults:
    set_fact:
      api_key: '{{kube_api_key}}'
      host: '{{kube_host}}'
  block:
    - name: Fetch a list of namespaces
      set_fact:
      projects: "{{ lookup('community.kubernetes.k8s', api_version='v1', kind='Namespace') }}" 

or should I specify api_key and host arguments every time?

tima commented 3 years ago

I don't think so @er1z. Your indention is off (set_fact under module_defaults should be over one) but I'm assuming that is just a typo.

Have you tried a k8s_info task and register that to a variable? That module and other k8s_ modules works with module_detaults groups. That is the more conventional approach to avoid setting api_key and host throughout a play and limiting those defaults to tasks in that group of modules without a block.

er1z commented 3 years ago

Yeah, just copied with an incorrect indent, now I redacted. Limiting is intentional because I need to pass previously fetched host name and token.

Gonna try later and post an update. Thanks.

er1z commented 3 years ago

Using k8s_info let me gather all required information with module_defaults. Thank you!