# Set (overlord) environment variable in playbook

**URL:** <https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544>\
**Category:** Ansible Project\
**Created:** [May 12, 2012, 6:14pm UTC](https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544 "2012-05-12T18:14:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 12, 2012, 6:14pm UTC](https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544/1 "2012-05-12T18:14:04Z")

</div>

I often (almost always) use bash scripts to do prep and cleanup on the overlord, and invoke ansible-playbook therefrom. I can easily pass data into ansible from the environment by setting --extra-vars, but I can’t think of a way to get data out of the playbook. E.g., I use fetch to download a file that my cleanup script needs to know about. Would a pseudo (local) module like this be accepted:?

action: setenv footar={$base\_dir}/foo.tar

In this case I would want to then untar the file in my bash script.

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 12, 2012, 6:32pm UTC](https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544/2 "2012-05-12T18:32:29Z")

</div>

Additionally, it would be very handy to have access ANSIBLE\_DARK\_HOSTS and ANSIBLE\_CONTACTED\_HOSTS as space-delimited environment variables.

---

<div class="post-metadata">

**Author:** ![Brice\_Burgess](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Brice\_Burgess](https://forum.ansible.com/u/Brice_Burgess)\
**Post date:** [January 25, 2013, 12:03am UTC](https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544/3 "2013-01-25T00:03:16Z")

</div>

I like the idea of `setenv`.

Is there a way that ansible can pass environment variables to the shell or command module? I’m running accross this issue when needing to set LEIN\_USERNAME, LEIN\_PASSWORD for a specific maven repo.

Thanks,

~ Brice

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [January 25, 2013, 12:49am UTC](https://forum.ansible.com/t/set-overlord-environment-variable-in-playbook/11544/4 "2013-01-25T00:49:27Z")

</div>

I'm pretty sure this won't work, the environment variables will expire  
after the program runs. export works in shell scripts only when you  
source the shell script. Otherwsie environment variables are read  
only. Such is Linux/Unix.

You could definitely use a logging callback to save what you were  
interested in JSON and have your script load that, or you could have  
ansible just invoke a local action at the end and call your script.

Or even write a config file or something basic from ansible.
