Set (overlord) environment variable in playbook

I often (almost always) use bash scripts to do prep and cleanup on the overlord, and invoke ansible-playbook therefrom. I can easily pass data into ansible from the environment by setting --extra-vars, but I can’t think of a way to get data out of the playbook. E.g., I use fetch to download a file that my cleanup script needs to know about. Would a pseudo (local) module like this be accepted:?

action: setenv footar={$base_dir}/foo.tar

In this case I would want to then untar the file in my bash script.

Additionally, it would be very handy to have access ANSIBLE_DARK_HOSTS and ANSIBLE_CONTACTED_HOSTS as space-delimited environment variables.

I like the idea of setenv.

Is there a way that ansible can pass environment variables to the shell or command module? I’m running accross this issue when needing to set LEIN_USERNAME, LEIN_PASSWORD for a specific maven repo.

Thanks,

~ Brice

I'm pretty sure this won't work, the environment variables will expire
after the program runs. export works in shell scripts only when you
source the shell script. Otherwsie environment variables are read
only. Such is Linux/Unix.

You could definitely use a logging callback to save what you were
interested in JSON and have your script load that, or you could have
ansible just invoke a local action at the end and call your script.

Or even write a config file or something basic from ansible.