I run my playbook with --limit option always so using ansible_limit I’m able to get the variable name of the group.
now depending on the group i need to get the hostname which is secondary as a variable.
id if --limit is group1, I need host1.vs.com as a var…how can i do that?
If i didn’t misunderstood, would you like to make use of inbuilt special variables to get hostname as - inventory_hostname, inventory_hostname_short which directly gives you hostname value and it can be stored in variable or printed using debug module.
PS :- You can also make use of facts to get hostname → parse it → store value in variable.
I did look at magic variables and i was not able to get what i wanted…
i basically want to get hostname which is of type secondary from group1 … so that i can store it in a var and use elsewhere…
iterating over hostvars data looks like a bug reported by few of them (found articles). tried but not able to iterate over hostvars using loop or with_items.