# question on variable references in 1.4

**URL:** <https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958>\
**Category:** Ansible Project\
**Created:** [November 21, 2013, 4:42pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958 "2013-11-21T16:42:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [November 21, 2013, 4:42pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/1 "2013-11-21T16:42:35Z")

</div>

Hello,

i’d like to do something like with ansible 1.4 :

mylist:

- key1: val1  
key2: “{{ key1 }}” # val1

- key1: val3  
key2: “{{ key1 }}” # val3

I tried different things (like key2: “{{ mylist[0].key1 }}”) but cannot seem to find a way to do it.

I agree this is a bit contrived but I was wondering if I am missing something.

can someone point me to the documentation where the zoo of possible references is explained ?

thank you

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 21, 2013, 4:56pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/2 "2013-11-21T16:56:31Z")

</div>

there is a yamllism for just pure reference (no concat or subsitution)

mylist:

- key1 : &key1reuse val1  
key2: \*key1reuse

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [November 21, 2013, 5:47pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/3 "2013-11-21T17:47:39Z")

</div>

Thank you that will do the trick in my case.

for reference, the message from Michael on the new variable references in 1.4 is  
[https://groups.google.com/forum/#!searchin/ansible-project/variable$20in$201.4/ansible-project/GzT3Mvukb1E/yMw8uorwoYwJ](https://groups.google.com/forum/#!searchin/ansible-project/variable$20in$201.4/ansible-project/GzT3Mvukb1E/yMw8uorwoYwJ)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 21, 2013, 6:48pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/4 "2013-11-21T18:48:07Z")

</div>

Right, you can’t reference a variable inside another, but “{{ foo }}” references structured variables fine in 1.4 otherwise.

(I’m not fond of YAML anchors, personally)

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [November 21, 2013, 6:56pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/5 "2013-11-21T18:56:36Z")

</div>

anyway yaml anchors don’t do concatenation as Brian mentionned.

In my case let’s say i want :

mylist:

- key1: a  
key2: b  
key3: a-b

- key1: c  
key2: d  
key3: c-d

what would be the best way to do that if i don’t want to carry “{{ item.key1 }}-{{ item.key2 }}” all over the place in the tasks ?

I have the case where key1 = application name, key2 = git sha of the application version  
and i want to install the versioned application in key1-key2 and make reference to that “install\_dir” in many places.

thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 23, 2013, 4:18pm UTC](https://forum.ansible.com/t/question-on-variable-references-in-1-4/13958/6 "2013-11-23T16:18:22Z")

</div>

" “{{ item.key1 }}-{{ item.key2 }}”"

Ansible variables bind late, so if you want to define a variable like so:

vars:  
item\_k1k2: “{{ item.key1 }} - {{ item.key2 }}”

It should work fine.

Though I’d pick a better variable name than what I picked above 🙂
