Ansible Inventory and http_proxy environment variables

31 views
Skip to first unread message

Bruno Cochofel

unread,
Nov 19, 2018, 12:41:46 PM11/19/18
to Ansible Project
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"?

Kai Stian Olstad

unread,
Nov 19, 2018, 1:13:55 PM11/19/18
to ansible...@googlegroups.com
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.


--
Kai Stian Olstad


Bruno Cochofel

unread,
Nov 20, 2018, 4:10:48 AM11/20/18
to ansible...@googlegroups.com
Thanks Kai, I'll give it a try.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3324947.aCTDG5Pn8n%40x1.
For more options, visit https://groups.google.com/d/optout.

Bruno Cochofel

unread,
Nov 20, 2018, 4:54:02 AM11/20/18
to Ansible Project
Hi,

That works :-)


On Tuesday, November 20, 2018 at 9:10:48 AM UTC, Bruno Cochofel wrote:
Thanks Kai, I'll give it a try.

On Mon, Nov 19, 2018 at 6:13 PM Kai Stian Olstad <ansible-project+list@olstad.com> wrote:
On Monday, 19 November 2018 18:41:46 CET Bruno Cochofel wrote:
> 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.combackup: bak.bos.example.comproxy_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.


--
Kai Stian Olstad


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages