Ansible - accessing local environment variables

alexs333 picture alexs333 · Jan 29, 2014 · Viewed 72.8k times · Source

I wonder if there is a way for Ansible to access local environment variables.

The documentation references accessing variable on the target machine:

{{ lookup('env', 'SOMEVAR') }}

Is there a way to access environment variables on the source machine?

Answer

grilix picture grilix · Jun 9, 2014

I have a Linux vm running on osx, and for me:

lookup('env', 'HOME') returns "/Users/Gonzalo" (the HOME variable from osx), while ansible_env.HOME returns "/root" (the HOME variable from the vm).

Worth to mention, that ansible_env.VAR fails if the variable does not exists, while lookup('env', 'VAR') does not fail.