# Is "environment" a reserved variable name?

**URL:** <https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838>\
**Category:** Ansible Project\
**Created:** [November 4, 2013, 2:06pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838 "2013-11-04T14:06:36Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 2:06pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/1 "2013-11-04T14:06:36Z")

</div>

Hi,

When I set the variable name “environment” and use it in a playbook, it is empty. Is it a reserved variable name?

Regards,  
Joost

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [November 4, 2013, 2:35pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/2 "2013-11-04T14:35:48Z")

</div>

Environment is a keyword for playbooks/tasks, however I don't think there's  
a direct issue with using it as a variable name. To be safe, you should  
probably use a different variable name anyway as it could be confused. If  
you change the name and still have issues, please post a sample of the  
playbook you're having problems with as well as information about the  
ansible version you're running (the output of "ansible --version").

See [http://www.ansibleworks.com/docs/playbooks\_environment.html](http://www.ansibleworks.com/docs/playbooks_environment.html) for more  
info about setting environment variables, if that's what you're trying to  
do.

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 2:42pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/3 "2013-11-04T14:42:36Z")

</div>

Well, I am using the word environment in the sense of “deployment environment”, but the term may be a bit general. Anyway, this is the playbook:

test.yml:

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [November 4, 2013, 2:49pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/4 "2013-11-04T14:49:07Z")

</div>

Ahh, you can’t do multiple “-e” options, just combine them: -e “foo=bar,environment=qux”

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 2:55pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/5 "2013-11-04T14:55:17Z")

</div>

Are you sure? This makes the output change into:

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK: [debug msg="{{environment}}"] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {"msg": "{}"}

TASK: [debug msg="bar,environment=qux"] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {"msg": "bar,environment=qux"}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=3 changed=0 unreachable=0 failed=0

But when I remove foo from the equation, environment is still empty:

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK: [debug msg="qux"] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {"msg": "{}"}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=2 changed=0 unreachable=0 failed=0

Regards,  
Joost

---

<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:** [November 4, 2013, 2:57pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/6 "2013-11-04T14:57:10Z")

</div>

Yes, environment is a restricted keyword. Initially specific within playbooks, but it gets injected in the runner:

inject[‘environment’] = self.environment

so it will erase whatever value was set by inventory of vars.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [November 4, 2013, 2:59pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/7 "2013-11-04T14:59:16Z")

</div>

Oops, my mistake, the variables should be space-separated, not comma-separated. So -e “foo=bar environment=qux”

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 3:01pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/8 "2013-11-04T15:01:03Z")

</div>

Thanks for the info. What is the runner environment?

And could I have found this out myself?

Regards,  
Joost

---

<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:** [November 4, 2013, 3:16pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/9 "2013-11-04T15:16:14Z")

</div>

> \> Yes, environment is a restricted keyword. [...]
> 
> Thanks for the info. What is the runner environment?

An ansible internal, it's the basic building block that "runs a task on a  
host"

> And could I have found this out myself?

​Depends if you are familiar with the ansible source code. I basically did  
a "grep environment​ lib/ -r" to double check this, you can find it in  
lib/ansible/runner/\_\_init\_\_.py

​If you have further questions on code, be sure to switch to the  
ansible-devel mailing list.

Serge​

---

<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:** [November 4, 2013, 3:16pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/10 "2013-11-04T15:16:43Z")

</div>

​That is actually quite confusing. Even as i use this a lot and have been  
for quite a while, I keep forgetting these details myself.  
I wonder what was the rationale to not allow for multiple -e options, which  
seem ​a lot easier to me.

Serge

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 3:20pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/11 "2013-11-04T15:20:54Z")

</div>

> > \> Yes, environment is a restricted keyword. [...]
> > 
> > Thanks for the info. What is the runner environment?
> 
> An ansible internal, it's the basic building block that "runs a task on a  
> host"

So is this an internal structure that is leaking out? Or is this  
something that could be interesting for a task?

> > And could I have found this out myself?
> 
> Depends if you are familiar with the ansible source code. [...]
> 
> If you have further questions on code, be sure to switch to the  
> ansible-devel mailing list.

Although the Ansible code is interesting, I was asking from a user's  
perspective. I was wondering if I overlooked some part of the  
documentation.

Regards,  
Joost

---

<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:** [November 4, 2013, 3:35pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/12 "2013-11-04T15:35:31Z")

</div>

> So is this an internal structure that is leaking out? Or is this  
> something that could be interesting for a task?

Not really leaking, no, it's just the structure that is using 'environment'  
and hence restriciting it for use to end users.  
​​

> Although the Ansible code is interesting, I was asking from a user's  
> perspective. I was wondering if I overlooked some part of the  
> documentation.

Sorry, I overshoot that one 🙂

I see it's mentioned here:

[http://www.ansibleworks.com/docs/playbooks\_variables.html#magic-variables-and-how-to-access-information-about-other-hosts](http://www.ansibleworks.com/docs/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts)  
​​

Serge

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 4, 2013, 6:33pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/13 "2013-11-04T18:33:38Z")

</div>

Thanks for the link, Serge!

Joost

---

<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 4, 2013, 11:33pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/14 "2013-11-04T23:33:13Z")

</div>

Let me correct this:

-e “foo=bar env=qux”

It’s key value pairs, just like the rest of ansible.

Also, don’t use environment, as it’s a reserved word 🙂

I think it would be nice if the system raised a warning when a variable named env was set, someone should perhaps file a ticket so we can add that 🙂

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [November 5, 2013, 11:52pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/15 "2013-11-05T23:52:21Z")

</div>

I am assuming you meant "environment" instead of "env", as the latter  
is not reserved and created a ticket:

[https://github.com/ansible/ansible/issues/4816](https://github.com/ansible/ansible/issues/4816)

Hope I got that right. Thanks!

Regards,  
Joost

---

<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 6, 2013, 2:10pm UTC](https://forum.ansible.com/t/is-environment-a-reserved-variable-name/13838/16 "2013-11-06T14:10:42Z")

</div>

yep, thanks!
