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
Could you resolve the issue? In case yes, i’d be happy to re-use whatever you came up with.
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)