I am trying to execute my task only when the host name has the variable servers=admin.
I am trying to execute the below playbook but I am facing an error.
I am trying this because it is similar to something which works for me like inventory_hostname in groups['production']. I would like to run the task only when the server variable has admin in it.
My host file:
[production]
host1 servers=admin,server1
host2 servers=server2
host3 servers=admin,server3
host4 servers=server4
host5 servers=server5
host6 servers=admin,server6
My task:
- name: run cmd
shell: hostname
register: op
when:
- inventory_hostvars in servers['admin']
My task should run only on host1, host3 and host6.