Last active
July 24, 2018 11:16
-
-
Save rparree/465f0236b37980d6394a0d9323f74d87 to your computer and use it in GitHub Desktop.
Proxy settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
vars: | |
proxy_address_without_credentials: http://{{host}}:{{port_no}} | |
_proxy_address_with_credentials: http://{{username}}:{{password}}@{{host}}:{{port_no}} | |
proxy_address_with_credentials: "{{proxy_address_without_credentials if username=='' else _proxy_address_with_credentials }}" | |
vars_prompt: | |
- name: host | |
prompt: "proxy host" | |
private: no | |
- name: port_no | |
prompt: "proxy port" | |
private: no | |
default: 8080 | |
- name: username | |
prompt: "proxy username" | |
private: no | |
- name: password | |
prompt: "proxy password" | |
private: yes | |
tasks: | |
- name: Ensure proxy set in .bashrc | |
blockinfile: | |
dest: "{{ ansible_env.HOME }}/.bashrc" | |
block: | | |
export {{item}}={{proxy_address_with_credentials}} | |
marker: '# {mark} proxy settings for {{item}}' | |
insertbefore: EOF | |
create: yes | |
with_list: | |
- http_proxy | |
- HTTP_PROXY | |
- https_proxy | |
- HTTPS_PROXY | |
- ftp_proxy | |
- FTP_PROXY | |
- all_proxy | |
- ALL_PROXY | |
- socks_proxy | |
- SOCKS_PROXY | |
- name: Ensure proxy set in .npmrc | |
blockinfile: | |
dest: "{{ ansible_env.HOME }}/.npmrc" | |
block: | | |
proxy={{proxy_address_with_credentials}} | |
https-proxy={{proxy_address_with_credentials}} | |
marker: '# {mark} proxy settings' | |
insertbefore: EOF | |
create: yes | |
- name: Ensure proxy set for docker in | |
block: | |
- blockinfile: | |
dest: /etc/systemd/system/docker.service.d | |
block: | | |
[Service] | |
Environment=HTTP_PROXY={{proxy_address_with_credentials}} | |
create: yes | |
- systemd: | |
state: restarted | |
daemon_reload: yes | |
name: docker | |
become: true | |
become_user: root | |
- name: Ensure proxy is applied to google chrome | |
ini_file: | |
dest: /usr/share/applications/google-chrome.desktop | |
option: Exec | |
section: "Desktop Entry" | |
value: "/usr/bin/google-chrome-stable %U --proxy-server={{proxy_address_without_credentials}} --proxy-bypass-list=localhost" | |
become: true | |
become_user: root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment