# reusing roles with environment proxy vars

**URL:** <https://forum.ansible.com/t/reusing-roles-with-environment-proxy-vars/14391>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 21, 2014, 4:35pm UTC](https://forum.ansible.com/t/reusing-roles-with-environment-proxy-vars/14391 "2014-01-21T16:35:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Peiser1](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Marc\_Peiser1](https://forum.ansible.com/u/Marc_Peiser1)\
**Post date:** [January 21, 2014, 4:35pm UTC](https://forum.ansible.com/t/reusing-roles-with-environment-proxy-vars/14391/1 "2014-01-21T16:35:25Z")

</div>

Hi there,

I’m reusing some roles between many hosts and I have a problem where some hosts require me to use a proxy for internet access. I want to know if there is an easy way to use the same role but only defining the environment http\_proxy variable for only those hosts that need it?

- name: "Install sysv-rc-conf on Ubuntu"  
&nbsp;&nbsp;apt: name=sysv-rc-conf state=present  
&nbsp;&nbsp;when: ansible\_distribution == 'Ubuntu'  
&nbsp;&nbsp;environment:  
&nbsp;&nbsp;&nbsp;&nbsp;http\_proxy: [http://172.16.0.1:8080](http://172.16.0.1:8080)

Thanks,  
Marc

---

<div class="post-metadata">

**Author:** ![Jochen\_Hinrichsen](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jochen\_Hinrichsen](https://forum.ansible.com/u/Jochen_Hinrichsen)\
**Post date:** [November 10, 2014, 2:28pm UTC](https://forum.ansible.com/t/reusing-roles-with-environment-proxy-vars/14391/2 "2014-11-10T14:28:47Z")

</div>

Could you resolve the issue? In case yes, i’d be happy to re-use whatever you came up with.

---

<div class="post-metadata">

**Author:** ![Marc\_Peiser1](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Marc\_Peiser1](https://forum.ansible.com/u/Marc_Peiser1)\
**Post date:** [November 25, 2014, 9:31pm UTC](https://forum.ansible.com/t/reusing-roles-with-environment-proxy-vars/14391/3 "2014-11-25T21:31:05Z")

</div>

All I did was add some proxy variables to my host\_vars for each host or group, for example:

# proxy settings

proxy: true  
proxy\_host: 172.16.228.1  
proxy\_port: 3128

And I’d reference those in my proxy configs like this:

http://{{ proxy\_host }}:{{ proxy\_port }}

In my proxy role, I have added tasks with ‘when: proxy’ to only run only when proxy is set to true.

- name: “Copy /etc/apt/apt.conf.d/00proxy for apt proxy configuration”  
� template: src=00proxy.j2 dest=/etc/apt/apt.conf.d/00proxy owner=root group=root mode=644  
� when: ansible\_distribution == ‘Ubuntu’ and proxy

If I don’t want to use the proxy role I just add ‘proxy: false’ to my host\_vars for that server.

I’d like an easier way to just exclude the proxy role from hosts that are set to false instead of adding when: proxy to each action.

> **(attachments)**
>
> ![postbox-contact.jpg](https://us1.discourse-cdn.com/ansible/original/2X/b/b1320ae411248fbd3dccf96ef55914bd1c865035.jpeg)
