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. [image: image.png] [image: image.png] [image: image.png]
On Mon, Aug 16, 2021 at 11:01 AM Saranya N <[email protected]> wrote: > I know i can use inventory_hostname but based on condition I want to get > that i.,e type secondary from group1 > > On Monday, August 16, 2021 at 11:00:02 AM UTC+5:30 Saranya N wrote: > >> H ello, >> >> 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... >> >> On Monday, August 16, 2021 at 10:36:52 AM UTC+5:30 [email protected] >> wrote: >> >>> HI Saranya, >>> >>> 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. >>> >>> Cheers, >>> Parth >>> >>> On Mon, Aug 16, 2021 at 10:29 AM Saranya N <[email protected]> wrote: >>> >>>> I need to get the hostname as a variable in my playbook >>>> >>>> I have the inventory defined the inventory like below >>>> >>>> [group1] >>>> host1.vs.com type=secondary servertype=vm >>>> host2.vs.com type=primary servertype=vm >>>> >>>> [group2] >>>> host4.vs.com type=primary servertype=physical >>>> host3.vs.com type=secondary servertype=physical >>>> >>>> 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? >>>> >>>> any help is appreciated, thank you >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ansible Project" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ansible-project/ea2efe68-3a9b-48bd-9925-d890ecc51fafn%40googlegroups.com >>>> <https://groups.google.com/d/msgid/ansible-project/ea2efe68-3a9b-48bd-9925-d890ecc51fafn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/2b03d3fb-7810-4f77-9ac6-cdad9977b41fn%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/2b03d3fb-7810-4f77-9ac6-cdad9977b41fn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEMGyLKddwCnHSoRUHHG%3DrPfs%2BNcStkVb2s1rDWcdDfOm9KXgA%40mail.gmail.com.
