ansible.cfg env variables

3,646 views
Skip to first unread message

Eric Palmer

unread,
Mar 21, 2013, 4:36:59 PM3/21/13
to ansible...@googlegroups.com
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

Nigel Metheringham

unread,
Mar 21, 2013, 5:09:51 PM3/21/13
to ansible...@googlegroups.com


Eric Palmer wrote:
> this does not work nor does various variations
> private_key_file=$HOME/keys/ec2-eXist-db.pem

Try
private_key_file=$ENV('HOME')/keys/ec2-eXist-db.pem
or
private_key_file=$LOOKUP('env','HOME')/keys/ec2-eXist-db.pem

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

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

Nigel.
--
[ Nigel Metheringham ------------------------------ ni...@dotdot.it ]
[ Ellipsis Intangible Technologies ]

Michael DeHaan

unread,
Mar 21, 2013, 5:09:54 PM3/21/13
to ansible...@googlegroups.com
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Lorin Hochstein

unread,
Mar 21, 2013, 5:14:40 PM3/21/13
to ansible...@googlegroups.com
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

Lorin Hochstein
Lead Architect - Cloud Services
Nimbis Services, Inc.

Michael DeHaan

unread,
Mar 21, 2013, 7:35:56 PM3/21/13
to ansible...@googlegroups.com
Don't think so :)

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

Jason Haury

unread,
Nov 20, 2013, 11:22:06 PM11/20/13
to ansible...@googlegroups.com
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!
Reply all
Reply to author
Forward
0 new messages