Ansible - accessing local environment variables

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?


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.


Use ansible lookup:

- set_fact: env_var="{{ lookup('env','ENV_VAR') }}"