# environment variables ISSUE "{{ lookup('env','HOME') }}"

**URL:** <https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439>\
**Category:** Ansible Project\
**Created:** [June 11, 2014, 2:28am UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439 "2014-06-11T02:28:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_Cano1](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Marcos\_Cano1](https://forum.ansible.com/u/Marcos_Cano1)\
**Post date:** [June 11, 2014, 2:28am UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439/1 "2014-06-11T02:28:27Z")

</div>

when running “{{ lookup(‘env’,‘HOME’) }}” what does ansible exactly do…

i’ve set a few variables in different files  
in  
/etc/environment  
/etc/profile

/root/.bashrc

/etc/bash.bashrc

and ansible does not recognize any of them but it does recognize PATH.

any suggestion?

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [June 11, 2014, 7:16am UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439/2 "2014-06-11T07:16:48Z")

</div>

Marcos Cano \<mcano@stsa.info\> napisał:

> when running "{{ lookup('env','HOME') }}" what does ansible exactly  
> do..

Step by step:  
- it looks for a lookup plugin 'env'  
- calls it with your args (WARNING: it does that locally, not on the remote!)  
- in case of this plugin, it returns a value from named environment variable

> i've set a few variables in different files  
> in  
> /etc/environment  
> /etc/profile  
> /root/.bashrc  
> /etc/bash.bashrc
> 
> and ansible does not recognize any of them but it does recognize PATH.

Are you sure you've exported them? In bash you have to export variables to make them visible to subprocesses (with "export VAR" after setting it, or just "export VAR=value").

> any suggestion?

Try to run ansible-playbook like:  
&nbsp;&nbsp;SOMEVAR=value ansible-playbook ...  
Then you can be sure that SOMEVAR is set.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 11, 2014, 6:52pm UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439/3 "2014-06-11T18:52:14Z")

</div>

There was also a bug in the early 1.6 branch (fixed in either 1.6.1 or 1.6.2) where the following resulted in an empty variable:

vars:  
HOME: “{{lookup(‘env’, ‘HOME’)}}”

This should be resolved in the latest stable release as well as in the devel branch, just in case that’s what you’re running into.

---

<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:** [June 11, 2014, 11:20pm UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439/4 "2014-06-11T23:20:19Z")

</div>

Also please be sure you’re aware lookup plugins execute on the ansible control machine, not the remotes.

(For those environment variables, there are facts available)

---

<div class="post-metadata">

**Author:** ![Marcos\_Cano1](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Marcos\_Cano1](https://forum.ansible.com/u/Marcos_Cano1)\
**Post date:** [June 11, 2014, 11:28pm UTC](https://forum.ansible.com/t/environment-variables-issue-lookup-env-home/15439/5 "2014-06-11T23:28:16Z")

</div>

Well I will check of I’m running that version because that’s exactly what’s happening, empty variables, also the funny thing about it is that the playbook is run loclahost, when I run env in the machine I do get all the variables right. But when running the playbook some of those variables are empty and so the result in my templates
