# 2 variables with same values being treated differently

**URL:** <https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178>\
**Category:** Ansible Project\
**Created:** [December 31, 2012, 10:21pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178 "2012-12-31T22:21:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [December 31, 2012, 10:21pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/1 "2012-12-31T22:21:27Z")

</div>

This is a head scratcher, well for me anyways.

I have two values that are being treated as if they weren’t equal, yet everything on the debug is showing me they have the same value.

In the playbook, the debug msg shows that $riak\_primary\_node $primary\_node have the same value, but when tested with when\_string: $riak\_primary\_node == $primary\_node they are shown not to be equal.

$riak\_primary\_node is derivced from a fact and $primary\_node is derived from : primary\_node: ${groups.tag\_stackName\_source\_primary}.

I’d like ${hostvars.${riak\_primary\_node}.ansible\_eth0.ipv4.address} to return a proper value, but it never does.

playbook, options, and output available here:

[https://gist.github.com/7b76b2cfc5704edd3738](https://gist.github.com/7b76b2cfc5704edd3738)

(don’t worry, those hosts have been terminated to protected the innocent).

Thanks,

James

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [January 1, 2013, 1:28am UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/2 "2013-01-01T01:28:53Z")

</div>

Possibly a string vs integer issue?

(ex: "0" vs 0, etc)

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [January 1, 2013, 5:35pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/3 "2013-01-01T17:35:22Z")

</div>

> Possibly a string vs integer issue?
> 
> (ex: "0" vs 0, etc)
> 
> I'm fairly certain that's not the case if you look at line 45 on the gist,

you can see

$riak\_primary\_node ${groups.tag\_stackName\_source\_primary}

being debugged and each have a value of  
ec2-184-72-193-106.compute-1.amazonaws.com  
ec2-184-72-193-106.compute-1.amazonaws.com

What I'm thinking is happing is that they are two different data types, one  
is a dictionary ($riak\_primary\_node) and is getting evaluated properly,  
and one is a string. So I guess then the question is, why can't I access  
the hostvars of the previous play by simply specify the target of the  
previous play by a string?

I've even tried

${hostvars.ec2-184-72-193-106.compute-1.amazonaws.com.ansible\_eth0.ipv4.address}

to no avail, and you clearly can see it was the target of the previous play.

Thanks,

James

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [January 1, 2013, 5:41pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/4 "2013-01-01T17:41:31Z")

</div>

Apologies for the formatted text on the previous reply. Had to find  
the magic triangle in GG to disable it.

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [January 1, 2013, 5:52pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/5 "2013-01-01T17:52:42Z")

</div>

James Martin wrote:

> This is a head scratcher, well for me anyways.
> 
> I have two values that are being treated as if they weren't equal, yet  
> everything on the debug is showing me they have the same value.
> 
> In the playbook, the debug msg shows that $riak\_primary\_node $primary\_node  
> have the same value, but when tested with when\_string:  
> $riak\_primary\_node == $primary\_node they are shown not to be equal.
> 
> $riak\_primary\_node is derivced from a fact and $primary\_node is derived  
> from : primary\_node: ${groups.tag\_stackName\_source\_primary}.

groups is a list. If you know it is only going to contain one node, you  
could use ${groups.tag\_stackName\_source\_primary[0]}, or change your test to  
be  
&nbsp;&nbsp;only\_if: "'$riak\_primary\_node' in $primary\_node"

Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [January 1, 2013, 5:54pm UTC](https://forum.ansible.com/t/2-variables-with-same-values-being-treated-differently/12178/6 "2013-01-01T17:54:25Z")

</div>

James Martin wrote:

> > Possibly a string vs integer issue?
> > 
> > (ex: "0" vs 0, etc)
> > 
> > I'm fairly certain that's not the case if you look at line 45 on the  
> > gist,
> 
> you can see
> 
> $riak\_primary\_node ${groups.tag\_stackName\_source\_primary}
> 
> being debugged and each have a value of  
> ec2-184-72-193-106.compute-1.amazonaws.com  
> ec2-184-72-193-106.compute-1.amazonaws.com
> 
> What I'm thinking is happing is that they are two different data types,  
> one  
> is a dictionary ($riak\_primary\_node) and is getting evaluated properly,  
> and one is a string. So I guess then the question is, why can't I access  
> the hostvars of the previous play by simply specify the target of the  
> previous play by a string?
> 
> I've even tried
> 
> ${hostvars.ec2-184-72-193-106.compute-1.amazonaws.com.ansible\_eth0.ipv4.address}

You have to escape the dots in the hostname, so make that  
${hostvars.{ec2-184-72-193-106.compute-1.amazonaws.com}.ansible\_eth0.ipv4.address}  
and it should do what you want.

Daniel
