I have a group of servers together in a site, where some of the servers have access only to a management network and not to the Internet, so I need to configure http_proxy for them to be able to pull packages, etc.
Now, I have a top-level playbook which I apply to all of the servers together, and I'm looking for a way to set the environment/http_proxy setting only for those servers that need it. Is there a way to somehow set the environment using host/group_vars?
I tried overriding the ansible_env
variable, but it doesn't work, I guess it's getting overwritten in the first playbook step (gather_facts
).
Apart from duplicating the plays in the playbook, limiting them to the group, and setting the environment there, is there any other way to achieve what I want?
Thanks in advance.
It seems not to be possible, as inventory variables are specific to ansible, they are not environment variables.
If the servers needs to have proxy_http
set put it directly on the server on any relevant file, like /etc/environment
to be system-wide or in your user profile files. This way ansible should use this transparently.
Furthermore the official ansible documentation suggest to use environment variable at task or play level.