reusing roles with environment proxy vars

60 views
Skip to first unread message

Marc Peiser

unread,
Jan 21, 2014, 11:35:25 AM1/21/14
to ansible...@googlegroups.com
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"
apt: name=sysv-rc-conf state=present
when: ansible_distribution == 'Ubuntu'
environment:
http_proxy: http://172.16.0.1:8080

Thanks,
Marc


Jochen Hinrichsen

unread,
Nov 10, 2014, 9:28:47 AM11/10/14
to ansible...@googlegroups.com
Could you resolve the issue? In case yes, i'd be happy to re-use whatever you came up with.

Marc Peiser

unread,
Nov 26, 2014, 9:29:22 AM11/26/14
to ansible...@googlegroups.com
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.

10 November 2014 at 4:28 PM
Could you resolve the issue? In case yes, i'd be happy to re-use whatever you came up with.


On Tuesday, 21 January 2014 17:35:25 UTC+1, Marc wrote:
--
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/ed342fee-2937-4568-9418-377b3db2961c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Marc Peiser       		    +27 71 678 5368
SensePost Information Security      +27 12 460 0880
pgp: www.sensepost.com/pgp/marc.txt
Reply all
Reply to author
Forward
0 new messages