# String to vars not working anymore in Ansible v1.8.x

**URL:** <https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590>\
**Category:** Ansible Project\
**Created:** [February 22, 2015, 1:35pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590 "2015-02-22T13:35:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khuong\_Dinh\_Pham](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khuong\_Dinh\_Pham](https://forum.ansible.com/u/Khuong_Dinh_Pham)\
**Post date:** [February 22, 2015, 1:35pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/1 "2015-02-22T13:35:39Z")

</div>

Hi

In v1.7.2 It was possible to do this i a template:

{{ vars[‘prefix\_’ + {{ item.env }} + ‘\_postfix’] | get\_something }}

But it’s not working anymore in v.1.8.x. It just say that variable ‘prefix\_main\_postfix’ does not exist in dict

Can i somehow concat a string and use it as variable name in Ansible v.1.8.x?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 22, 2015, 1:44pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/2 "2015-02-22T13:44:18Z")

</div>

​I'm not sure this would have worked in older versions.​ Either way, don't  
nest those braces, just use plain variables:

​{{ vars['prefix\_' + item.env + '\_postfix'] | get\_something }}

---

<div class="post-metadata">

**Author:** ![Khuong\_Dinh\_Pham](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khuong\_Dinh\_Pham](https://forum.ansible.com/u/Khuong_Dinh_Pham)\
**Post date:** [February 22, 2015, 6:30pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/3 "2015-02-22T18:30:42Z")

</div>

Hi

Typo error. I meant

​{{ vars[‘prefix\_’ + item.env + ‘\_postfix’] | get\_something }}

This is not working anymore in v1.8.4 If I switch back to v.1.7.2 it’s working fine.

However if I type

​{{ prefix\_main\_postfix | get\_something }} in v.1.8.4 it’s working fine

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 22, 2015, 6:38pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/4 "2015-02-22T18:38:10Z")

</div>

​Your latter example strike me as being obvious.​  
Is the varsdict meant to be something special?

---

<div class="post-metadata">

**Author:** ![Khuong\_Dinh\_Pham](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khuong\_Dinh\_Pham](https://forum.ansible.com/u/Khuong_Dinh_Pham)\
**Post date:** [February 22, 2015, 7:04pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/5 "2015-02-22T19:04:59Z")

</div>

Maybe it obvious but it is just to tell you that the variable exist. We use the vars like this:

myvars.yml:  
prefix\_main\_postfix: some\_value

master yml:

---

<div class="post-metadata">

**Author:** ![Jonathan\_Davila](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jonathan\_Davila](https://forum.ansible.com/u/Jonathan_Davila)\
**Post date:** [February 23, 2015, 3:34pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/6 "2015-02-23T15:34:08Z")

</div>

Try taking out the middle curly braces. So like:

{{ ‘prefix\_’ + item.env + ‘\_postfix’ | get\_something }}

If you are declaring vars with the vars construct, you don’t need to reference vars as a dict, the key/values are directly available.

Let me know if that helps.

---

<div class="post-metadata">

**Author:** ![Khuong\_Dinh\_Pham](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khuong\_Dinh\_Pham](https://forum.ansible.com/u/Khuong_Dinh_Pham)\
**Post date:** [February 23, 2015, 8:02pm UTC](https://forum.ansible.com/t/string-to-vars-not-working-anymore-in-ansible-v1-8-x/17590/7 "2015-02-23T20:02:54Z")

</div>

Hi

It does not work because get\_something can’t parse the string “prefix\_main\_postfix” I need the value.

If I remove “| get\_something” like this:

{{ ‘prefix\_’ + item.env + ‘\_postfix’ }}

it just print the text ‘prefix\_main\_postfix’
