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
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.
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.
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
Don't think so
I'd recommend just using the environment variable if you want that
kind of behavior.
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!