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

On Mon, Dec 6, 2021 at 9:54 PM Todd Lewis <uto...@gmail.com> wrote:

> 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*
> ---
> - name: Demo for accessing inventory group variables
>   # ansible-playbook groupvars.yml -i ./groupvars-inventory.ini -v
>   hosts: localhost
>   tasks:
>     - name: Gather the ansible_host values from hosts in the test group
>       set_fact:
>         test_ips: |
>           {%- set ip=[] -%}
>           {%- for h in groups['test'] -%}
>           {%-   set _ = ip.append(hostvars[h]['ansible_host']) -%}
>           {%- endfor %}{{ ip }}
>
>     # TASK [Gather the ansible_host values from hosts in the test group]
> ****
>     # ok: [localhost] => changed=false
>     #   ansible_facts:
>     #     test_ips:
>     #     - 1.1.1.1
>     #     - 2.2.2.2
>
>
>     - name: Same thing but with legit filters in the dev group
>       set_fact:
>         dev_ips: "{{ groups['dev']|map('extract',hostvars,'ansible_host')
> }}"
>
>     # TASK [Same thing but with legit filters in the dev group] ****
>     # ok: [localhost] => changed=false
>     #   ansible_facts:
>     #     dev_ips:
>     #     - 3.3.3.3
>     #     - 4.4.4.4
>
>
> On Friday, December 3, 2021 at 3:02:19 AM UTC-5 jiten...@zscaler.com
> wrote:
>
>> 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
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-devel/118fce13-6ff8-4de3-85e0-90f8e85448f3n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-devel/118fce13-6ff8-4de3-85e0-90f8e85448f3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

*Regards,*
*Jitender*

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/CAMO4JZtGtOGfa1w9gw8KcbXvDk3S25CYC33TBTPYLQuhw8rv3w%40mail.gmail.com.

Reply via email to