# Variable indirection

**URL:** <https://forum.ansible.com/t/variable-indirection/28644>\
**Category:** Ansible Project\
**Created:** [September 25, 2018, 3:30pm UTC](https://forum.ansible.com/t/variable-indirection/28644 "2018-09-25T15:30:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erichymowitz](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@erichymowitz](https://forum.ansible.com/u/erichymowitz)\
**Post date:** [September 25, 2018, 3:30pm UTC](https://forum.ansible.com/t/variable-indirection/28644/1 "2018-09-25T15:30:53Z")

</div>

Greetings.

I feel like I’ve done this before, but for some reason, I can’t figure it out.

I’ve got two hashes defined.

password\_change:  
cobbler: [ebhpw]

cougar: [ehymowitz]

password\_groups:  
ebhpw: ehymowitz

Then I’ve got a play.

- name: eric testing 9  
debug:  
msg: “it worked!!! variable is {{password\_change.cobbler}}”  
when:
- password\_change.cobbler is defined

This works:

TASK [eric testing 9]  
ok: [gs-444-e10285] =\> {  
“msg”: “it worked!!! variable is [u’ebhpw’]”  
}

I don’t fully understand what the brackets and the u are for. But I think that’s getting in my way. Because now I’m trying to do this:

- name: eric testing 9  
debug:  
msg: “it worked!!! variable is {{password\_change.cobbler}}”  
when:
- password\_change.cobbler is defined
- password\_groups[password\_change.cobbler] is defined

and it fails.

TASK [eric testing 9]  
skipping: [gs-444-e10285]

So what am I missing? It knows what password\_change.cobbler is (“ebhpw”) , and it knows what password\_groups[ebhpw] is (“ehymowitz”), so why I can’t I properly test for the value of password\_groups[password\_change.cobbler] ?

Thanks.

–EbH

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 28, 2018, 7:51pm UTC](https://forum.ansible.com/t/variable-indirection/28644/2 "2018-09-28T19:51:18Z")

</div>

> Greetings.
> 
> I feel like I've done this before, but for some reason, I can't figure it  
> out.
> 
> I've got two hashes defined.
> 
> password\_change:  
> &nbsp;&nbsp;cobbler: [ebhpw]  
> &nbsp;&nbsp;cougar: [ehymowitz]

If you don't understand the brackets, why are you using them here?

> password\_groups:  
> &nbsp;&nbsp;ebhpw: ehymowitz
> 
> Then I've got a play.
> 
> &nbsp;&nbsp;- name: eric testing 9  
> &nbsp;&nbsp;&nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "it worked!!!! variable is {{password\_change.cobbler}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;when:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- password\_change.cobbler is defined
> 
> This works:
> 
> TASK [eric testing 9]  
> ok: [gs-444-e10285] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "it worked!!!! variable is [u'ebhpw']"  
> }
> 
> I don't fully understand what the brackets and the u are for.

List(array) in Ansible can be written in two ways.

myvar: ["one","two"]

or

myvar:  
&nbsp;&nbsp;- one  
&nbsp;&nbsp;- two

u is Pythons way of saying that the element in the list is unicode.

> But I think  
> that's getting in my way. Because now I'm trying to do this:

Then you shouldn't use them in the first place.

> &nbsp;&nbsp;- name: eric testing 9  
> &nbsp;&nbsp;&nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "it worked!!!! variable is {{password\_change.cobbler}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;when:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- password\_change.cobbler is defined  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- password\_groups[password\_change.cobbler] is defined
> 
> and it fails.
> 
> TASK [eric testing 9]  
> skipping: [gs-444-e10285]
> 
> So what am I missing? It knows what password\_change.cobbler is ("ebhpw") ,  
> and it knows what password\_groups[ebhpw] is ("ehymowitz"), so why I can't I  
> properly test for the value of password\_groups[password\_change.cobbler] ?

password\_change.cobbler is not "ebhpw" it's list since you have the values between , but password\_change.cobbler.0 does contain "ebhpw"

---

<div class="post-metadata">

**Author:** ![erichymowitz](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@erichymowitz](https://forum.ansible.com/u/erichymowitz)\
**Post date:** [October 1, 2018, 11:52am UTC](https://forum.ansible.com/t/variable-indirection/28644/3 "2018-10-01T11:52:03Z")

</div>

Thank you very much. That was the little push I needed. I think I've got it now.

--EbH
