# Global HTTP proxy setting for all roles/tasks?

**URL:** <https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786>\
**Category:** Ansible Project\
**Created:** [March 19, 2015, 9:08am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786 "2015-03-19T09:08:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [March 19, 2015, 9:08am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/1 "2015-03-19T09:08:02Z")

</div>

Hi,

We’re working in an environment where all access outside needs to go through HTTP/HTTPS proxies. We have previously solved this by defining a global environment variable with the necessary proxy definitions (http\_proxy, https\_proxy, no\_proxy) and then have passed that down to each task with “environment”. But this means we need to patch most public/external playbooks for the tasks that require external access (e.g. package installs, resource download etc).

Is there any way to make the proxy environment automatically available for all tasks without adding the “environment: proxy\_env” for all individual tasks?

Thanks,  
Timo

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 19, 2015, 9:14am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/2 "2015-03-19T09:14:52Z")

</div>

AFAIK, that is not possible, but it would be an important feature. Proxy support is too often forgotten in a lot of applications.

---

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [March 19, 2015, 9:28am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/3 "2015-03-19T09:28:49Z")

</div>

This is a real pain for us when setting up environments with multiple components & the need to add the proxy settings for each role/task. E.g. setting up something like Maven/Mesos/Chronos/Marathon + Docker requires numerous patches (adding the environments for individual tasks) for each role.

Is there some technical constraint that makes this difficult to implement?

---

<div class="post-metadata">

**Author:** ![Jon\_Soul](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@Jon\_Soul](https://forum.ansible.com/u/Jon_Soul)\
**Post date:** [March 19, 2015, 11:18am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/4 "2015-03-19T11:18:18Z")

</div>

I recently came up against the same problem. There was a pull request to support play level environment keyword and it was merged not too long ago.

[https://github.com/ansible/ansible/pull/8651](https://github.com/ansible/ansible/pull/8651)

I’m setting an environment variable in a group\_vars file that filters down to all tasks run against that group.

`environment: http_proxy: http://proxy.com:8080 https_proxy: http://proxy.com:8080`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 19, 2015, 1:19pm UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/5 "2015-03-19T13:19:14Z")

</div>

so is play level environment support enough?

---

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [March 20, 2015, 9:02am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/6 "2015-03-20T09:02:47Z")

</div>

This is excellent, thanks a lot for the pointer. We’ll give this a try with a newer Ansible version…

---

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [March 22, 2015, 7:07am UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/7 "2015-03-22T07:07:52Z")

</div>

Hi Brian,

Play level helps (compared to task level configuration), but ideally it would be possible to set this for the whole playbook.

---

<div class="post-metadata">

**Author:** ![Barry\_Flanagan](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Barry\_Flanagan](https://forum.ansible.com/u/Barry_Flanagan)\
**Post date:** [March 27, 2015, 2:09pm UTC](https://forum.ansible.com/t/global-http-proxy-setting-for-all-roles-tasks/17786/8 "2015-03-27T14:09:36Z")

</div>

I do the following, which will install /etc/profile.d/proxy.sh and /etc/apt/apt.conf.d/02-apt-cacher if the host does not have a valid default route, and ensures it is not present if it does. You could do something similar and then have a further task at the end of your playbook to remove them again if you don’t want them always present.

- name: make sure proxy is not used on hosts with a default route.  
file:  
dest: /etc/profile.d/proxy.sh  
state: absent  
when: ansible\_default\_ipv4.gateway is defined and ansible\_default\_ipv4.gateway | match(“^87.232”)

- name: install http proxy env profile  
template:  
dest: /etc/profile.d/proxy.sh  
mode: 0755  
src: profile-proxy.sh  
when: ansible\_default\_ipv4.gateway is not defined or ansible\_default\_ipv4.gateway | match(“^10.5”)

- name: Remove /etc/apt/apt.conf.d/02-apt-cacher on hosts with a default route.  
file:  
dest: /etc/apt/apt.conf.d/02-apt-cacher  
state: absent  
when: ansible\_default\_ipv4.gateway is defined and ansible\_default\_ipv4.gateway | match(“^87.232”)

- name: install /etc/apt/apt.conf.d/02-apt-cacher  
template:  
dest: /etc/apt/apt.conf.d/02-apt-cacher  
mode: 0755  
src: apt-cacher.conf  
when: ansible\_default\_ipv4.gateway is not defined or ansible\_default\_ipv4.gateway | match(“^10.5”)

Hope this helps.

-Barry Flanagan
