Variable in a variable

Hi,
In a Jijna2 template I need a following variable from hostvars.

hostvars['{{project}}-example.com'].ansible_eth0.ipv4.address

As you can see part of the hostname is dynamical created based
external variable. I don't think such operation is possible. However,
I wonder if there is any way to access such a variable.

Thanks,
Wawrzek

Have you tried that? We used to use hostvars a lot* and I'm sure I'd
have done something like
this previously.

* (we got rid of them in the end because if 'project'-example.com was
down, ansible couldn't run
    on any other boxes. In the end we to solve your sort of problem we
just added DNS entries for
    those IPs and set vars explicitly in the plays)

In a Jijna2 template I need a following variable from hostvars.

hostvars['{{project}}-example.com'].ansible_eth0.ipv4.address

I'm pretty sure something like

  hostvars[project + '-example.com'].ansible_eth0.ipv4.address

will work. You might need to bracket-ify the whole thing, like

  hostvars[project + '-example.com']['ansible_eth0']['ipv4']['address']

Not sure about that, I don't have a good sense of when Jinja lets you use
dots to mean keys in a dict, and when it doesn't. And how it knows which
are variables and which are literals. Anyway, something like that.

                                      -Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

> In a Jijna2 template I need a following variable from hostvars.
>
> hostvars['{{project}}-example.com'].ansible_eth0.ipv4.address

[...]

will work. You might need to bracket-ify the whole thing, like

  hostvars[project + '-example.com']['ansible_eth0']['ipv4']['address']

Seems to work.

Thanks,
Wawrzek