How to pass http proxy to ansible using environment variables?

Spread the Knowledge

It is quite possible that you may need to get package updates through a proxy, or even get some package updates through a proxy and access other packages not through a proxy. Or maybe a script you might wish to call may also need certain environment variables set to run properly.

Ansible makes it easy for you to configure the remote execution environment by using the ‘environment’ keyword. Here is an example:

The environment can also be stored in a variable, and accessed like so:

You can also use it at a play level:

While just proxy settings were shown above, any number of settings can be supplied. The most logical place to define an environment hash might be a group_vars file, like so: