# ansible.cfg env variables

**URL:** <https://forum.ansible.com/t/ansible-cfg-env-variables/12554>\
**Category:** Ansible Project\
**Created:** [March 21, 2013, 8:36pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554 "2013-03-21T20:36:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Palmer1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Eric\_Palmer1](https://forum.ansible.com/u/Eric_Palmer1)\
**Post date:** [March 21, 2013, 8:36pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/1 "2013-03-21T20:36:59Z")

</div>

I’m just learning today somethings about ansible

We will be automating the install of some open source xml db software.

I have set up a ansible.cfg and a small bash script that just calls ansible with some arguments

It all works and talks to a ec2 instance

Now I want to use env vars in the ansible.cfg file

this does not work nor does various variations  
private\_key\_file=$HOME/keys/ec2-eXist-db.pem

I have checked and home is defined

if I hard code the path it works

thanks in advance.

Eric Palmer

U of Richmond

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [March 21, 2013, 9:09pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/2 "2013-03-21T21:09:51Z")

</div>

Eric Palmer wrote:

> this does not work nor does various variations  
> private\_key\_file=$HOME/keys/ec2-eXist-db.pem

Try  
&nbsp;&nbsp;private\_key\_file=$ENV('HOME')/keys/ec2-eXist-db.pem  
or  
&nbsp;&nbsp;private\_key\_file=$LOOKUP('env','HOME')/keys/ec2-eXist-db.pem

See:-  
[http://ansible.cc/docs/playbooks2.html#lookup-plugins-accessing-outside-data](http://ansible.cc/docs/playbooks2.html#lookup-plugins-accessing-outside-data)

[that is a single URL which may wrap in mail]

&nbsp;&nbsp;Nigel.

---

<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:** [March 21, 2013, 9:09pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/3 "2013-03-21T21:09:54Z")

</div>

If you want to use local env variables, it's like this

some\_var: $ENV('HOME')

Your config management should not rely on remote environment variables  
for paths. You can of course use ~/ and such.

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [March 21, 2013, 9:14pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/4 "2013-03-21T21:14:40Z")

</div>

On this topic:

If I want to append to (but not overwrite) the ANSIBLE\_LIBRARY path in the config file, how can I do that? For example, assume that I have a directory relative to ansible.cfg called acme-custom-modules, I’d like to do the equivalent of:

library = $ANSIBLE\_LIBRARY:./acme-custom-modules

(Or does just work?)

Lorin

---

<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:** [March 21, 2013, 11:35pm UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/5 "2013-03-21T23:35:56Z")

</div>

Don't think so 🙂

I'd recommend just using the environment variable if you want that  
kind of behavior.

---

<div class="post-metadata">

**Author:** ![Jason\_Haury](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@Jason\_Haury](https://forum.ansible.com/u/Jason_Haury)\
**Post date:** [November 21, 2013, 4:22am UTC](https://forum.ansible.com/t/ansible-cfg-env-variables/12554/6 "2013-11-21T04:22:06Z")

</div>

Actually, you sure can! this syntax in the ansible.cfg file works just fine:  
library = /usr/share/ansible:/home/me/cm/ansible/modules

if you notice the default value for remote\_tmp, you see that system variables can be used too:

remote\_tmp = $HOME/.ansible/tmp

Enjoy!
