Ansible Inventory and http_proxy environment variables

Hi,

I have more then one DC, one with proxy and the other with no proxy. Almost all my servers are on the DC that has proxy.
Can I set something like (taken from ansible documentation):

---
# file: group_vars/boston

ntp_server: ntp.bos.example.com
backup: bak.bos.example.com
proxy_env:
  http_proxy: http://proxy.bos.example.com:8080
  https_proxy: http://proxy.bos.example.com:8080
and use
environment: "{{proxy_env}}"
but for the other hosts undefined/unset the proxy_env and don't use the "environment"?

I think this should work, in group_vars/all set proxy_env to empty dict so you don't get undefined variable.
proxy_env: {}

Then you can set proxy_env to a proper value in the group_vars or host_vars depending on your requirement.

Thanks Kai, I’ll give it a try.

Hi,

That works :slight_smile: