# Variable substitution and with\_items

**URL:** <https://forum.ansible.com/t/variable-substitution-and-with-items/16242>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [September 16, 2014, 12:36pm UTC](https://forum.ansible.com/t/variable-substitution-and-with-items/16242 "2014-09-16T12:36:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Moreira](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jose\_Moreira](https://forum.ansible.com/u/Jose_Moreira)\
**Post date:** [September 16, 2014, 12:36pm UTC](https://forum.ansible.com/t/variable-substitution-and-with-items/16242/1 "2014-09-16T12:36:48Z")

</div>

Hello,

my company (me) recently started using Ansible (1.7.1) for multi-stage server provisioning (both on local vagrant and ec2). Even though i haven’t utilized the variable much, i have defined:

environment: production

on the environment specific group\_vars file; its value can be “development”, “production”, “staging”, etc. In the same group\_vars file, for provisioning Postgresql databases i am utilizing the “ANXS.postgresql” Galaxy module and defining databases in variables as well:

postgresql\_databases:

- name: app\_production  
hstore: yes  
uuid\_ossp: no

I had initially planned to suffix the environment variable in the database name (not only on databases but other sections of the playbooks) :

postgresql\_databases:

- name: app\_{{ environment }}  
hstore: yes  
uuid\_ossp: no

but the resulting database name after substitution becomes “app\_{}” and i believe it is related, but not only, to the database task using with\_items:

- name: PostgreSQL | Make sure the PostgreSQL databases are present  
postgresql\_db:  
name: “{{item.name}}”  
encoding: “{{postgresql\_encoding}}”  
lc\_collate: “{{postgresql\_locale}}”  
lc\_ctype: “{{postgresql\_locale}}”  
template: “template0”  
state: present  
with\_items: postgresql\_databases  
when: postgresql\_databases|length \> 0

Is it possible to use this substitution pattern (utilizing variables with other variables in its value as a list value), or am i just using the wrong pattern and just use explicit names (name\_X instead of name\_{{ var1 }}) ?

Thank you

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 16, 2014, 12:46pm UTC](https://forum.ansible.com/t/variable-substitution-and-with-items/16242/2 "2014-09-16T12:46:15Z")

</div>

The variable name “environment” is a reserved variable name and used as described at [http://docs.ansible.com/playbooks\_environment.html](http://docs.ansible.com/playbooks_environment.html)

You should use something such as “env” or “environ” instead.

---

<div class="post-metadata">

**Author:** ![Jose\_Moreira](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jose\_Moreira](https://forum.ansible.com/u/Jose_Moreira)\
**Post date:** [September 16, 2014, 12:53pm UTC](https://forum.ansible.com/t/variable-substitution-and-with-items/16242/3 "2014-09-16T12:53:34Z")

</div>

Awesome, thank you!

Terça-feira, 16 de Setembro de 2014 13:47:03 UTC+1, Matt Martz escreveu:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 16, 2014, 3:13pm UTC](https://forum.ansible.com/t/variable-substitution-and-with-items/16242/4 "2014-09-16T15:13:20Z")

</div>

We have proposed changing this to something much less likely to be clobbered.

If someone would like to file a ticket, or send a pull request to make this automagic use a variable like “ansible\_environment\_settings” or something, we’ll definitely consider changing it.

This has come up a handful of times, and while documented, it would be nice to not have the potential confusion.
