Print Hostvar For All Host Under Group

Hi Team,

Need your help got stuck

I want to use host vars from inventory for all host under a specific group

I tried with the below example but only getting IP when I am passing hostname not getting anything when trying to get ansbile_host variable value for all host under that group with the group name

ip: “{{hostvars[‘test’][‘ansible_host’]}}” ------Not working

ip: “{{hostvars[‘test1’][‘ansible_host’]}}” -------- Working

[test]
test1 ansible_host=1.1.1.1
test2 ansible_host=2.2.2.2

Hello,

This doesn’t look like its a supported way, you can use index of one and access but not full group:

https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-access-a-group-variable

  • Jamer

Thanks …any other way to use hosname wildcard

“{{hostvars[‘test’][‘ansible_host’]}}”

Is this what you’re looking for?
$ cat groupvars-inventory.ini
[test]
test1 ansible_host=1.1.1.1
test2 ansible_host=2.2.2.2

[dev]
dev1 ansible_host=3.3.3.3
dev2 ansible_host=4.4.4.4

$ cat groupvars.yml

Thanks @Todd, First solution is working for me… thank you very much