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

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?

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:
  SOMEVAR=value ansible-playbook ...
Then you can be sure that SOMEVAR is set.

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.

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)

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