B
B
bigazzzz2021-05-12 17:48:39
Ansible
bigazzzz, 2021-05-12 17:48:39

How to read variables in ansible by separate group?

Good afternoon!
There is an inventory file.

cluster:
          children:
            masters:
              hosts:
                K8s-Master01:
                  ansible_host: 192.168.0.2
            workers:
              hosts:
                K8s-Node01:
                  ansible_host: 192.168.0.3
                K8s-Node02:
                  ansible_host: 192.168.0.4
                  taints:
                  - dedicated=true:NoSchedule

I need to "pollute" the nodes based on the inventory, i.e. on master execute kubectl taint nodes
Something like
- name: Apply taints
    shell: "kubectl taint nodes {{ item | lower }} {{ hostvars['{{ item }}']['taints'] }}"
    with_items: "{{ groups.workers }}"

Of course, the {{ hostvars['{{ item }}']['taints'] }} construct doesn't work. Are there workarounds?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MaxKozlov, 2021-05-12
@MaxKozlov

As far as I remember, through groups['workers'] you can get to the hosts. well, that one is already extractors of deeper-- data

P
Puma Thailand, 2021-05-12
@opium

For a recipe, you can simply specify a group in the hosts

M
mureevms, 2021-05-13
@mureevms

How I solved this problem https://notessysadmin.com/how-to-get-a-variable-fr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question