On Fri, Sep 5, 2014 at 7:56 PM, <[email protected]> wrote:

> hostvars['somehost']['ansible_default_ipv4'].address
>
> inventory_hostname is a var worth mentioning: it's the hostname of the
> local system. useful for:
> hostvars[inventory_hostname]['ansible_default_ipv4']
>

This can be simplified just down to:

{{ ansible_default_ipv4 }}

however.

It can be useful for when you need to fish out a variable name
programmatically though.

{{ hostvars[inventory_hostname]["some_variable"][name_of_hash_key] }}

etc




>
> there's also a 'groups' top-level var you can use to iterate through the
> inventory, which may or may not be
> better than iterating through hostvars to get your list of hosts. pardon,
> been a couple months since i touched
> that particular use-case.
>
> On Fri, Sep 05, 2014 at 02:35:55PM -0700, Matt Hughes wrote:
> > As far as I understand it, fact variables are exposed for the *current*
> > server that Ansible is operating on.  So if I say: {{
> > ansible_default_ipv4.address }}, that is going to get evaluated for each
> > host as I perform some operation using that variable.
>
> > hosts={% for fact in facts %}
> >    {{ fact['ansible_default_ipv4.address'] }},
> > {% endfor %}
>
> > and have that evaluated to "98.0.0.1,98.0.0.2,98.0.0.3"
>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/20140905235612.GC4709%40voodoowarez.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzyOYGvcDjW7XbzgQ%3DePOff7GPTAVEjZQC6-s7Wq1TO_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to