On Tue, Mar 25, 2014 at 8:39 AM, C. Morgan Hamill <[email protected]>wrote:

> Excerpts from Matt Coddington's message of 2014-03-24 22:58:50 -0400:
> > Using Ansible 1.5.3
> >
> > I'm having some trouble with a situation where I have a variable that I'd
> > like to use in a template that uses "hostvars" but the variable in
> question
> > is calculated from facts.
> >
> > I have a template that looks like this:
> >
> > {% for host in groups['uat4-webapp']|sort %}
> > BalancerMember ajp://{{ hostvars[host].webapp_ip }}:8009 loadfactor=20
> > {% endfor %}
> >
> > The "webapp_ip" variable is calculated like this in a group_vars file:
> >
> > webapp_ip: "{{ ansible_eth0.ipv4.address }}"
>
> > Is this something that should work, or should I be looking to accomplish
> > this a different way?
>
> Ansible seems to evaluate somewhat lazily, so
> "{{ansible_eth0.ipv4.address}}"
> get evaluated in the context of the current host.
>
> You'll probably need to be explicit:
>
>     {{ hostvars[host].ansible_eth0.ipv4.address }}
>

Thanks Morgan,
That's what i was afraid of... you're correct that explicitly referencing
those does work, and I can do this in the template by having different
cases for the different sets of servers (e.g. "if prod, use
ansible_bond0.ipv4.address, if staging use ansible_eth0.ipv4.address,
etc").  I was just hoping there was a way to abstract that if/then logic
into a common variable outside the template.

thanks,
matt

-- 
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/CAMfrSccM6X7tWM-BpjFyCYttiqCt5TQSaRM06D%2B800QtYcP_cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to