On 23.02.2019 18:53, [email protected] wrote:
> Hello all,
>
> I have an inventory file populated with two hosts and I would like to use
> the value of host B's variable on host A. I had no luck with using hostvars
> in the template.
>
> Example inventory file. Note this will be a dynamically generated file.
>
> [host_a]
> x.x.x.x
> [host_a:vars]
> eth0=192.168.1.1
> eth1=192.168.2.1
>
>
> [host_b]
> x.x.x.x
> [host_b:vars]
> eth0=192.168.1.2
> eth1=192.168.2.2
>
> I want to use 192.168.2.1 from host_a's variable in a template that will
> generate a config file on both host a and b. For example, the config on
> both hosts will have an entry like this: clustered_ips = 192.168.2.1,
> 192.168.2.2
>
> I tried this in the template file but get undefined variable.
>
> {{ hostvars[host_a][eth0] }}
Without quotes inside [] they are taken as variables, so host_a and eth0 is
taken as variables.
So you're looking for this
{{ hostvars['host_a']['eth0'] }}
--
Kai Stian Olstad
--
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/18e47086-e90e-6f41-b852-23c00cb3a5db%40olstad.com.
For more options, visit https://groups.google.com/d/optout.