From d55c453197710967763e8d2dded22f8751c0a51f Mon Sep 17 00:00:00 2001 From: Paul Kehle Date: Tue, 22 Nov 2016 08:30:59 -0500 Subject: [PATCH 1/2] Initial commit. Sets up /etc/environment, /etc/profile.d/proxy.sh, /etc/apt/apt.conf.d/80proxy, git --- .gitattributes | 2 ++ .gitignore | 1 + .travis.yml | 15 ++++++++ README.md | 32 +++++++++++++++-- defaults/main.yml | 2 ++ meta/main.yml | 13 +++++++ tasks/main.yml | 88 +++++++++++++++++++++++++++++++++++++++++++++++ templates/.keep | 0 vars/main.yaml | 2 ++ 9 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/.keep create mode 100644 vars/main.yaml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..11bba78 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.yaml linguist-language=Ruby +*.yml linguist-language=Ruby diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4668340 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +--- +language: python +python: "2.7" +before_install: + - sudo apt-get update -qq + - sudo apt-get install -qq python-apt python-pycurl +install: + - pip install ansible +script: + - echo travis.dev > inventory + - ansible-playbook -i inventory --syntax-check --list-tasks test.yml + - ansible-playbook -i inventory --extra-vars "sc_common_name=travis.dev" --connection=local --sudo -vvvv test.yml +addons: + hosts: + - travis.dev diff --git a/README.md b/README.md index 3820c1a..0def449 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ -# ansible-proxy-setup -Enable a Proxy Server for a VM +# Ansible: proxy-setup + +Configure packages to use a Proxy Server + +Available on Ansible Galaxy: [pgkehle.proxy-setup](https://galaxy.ansible.com/pgkehle/proxy-setup) + + +# Examples + +```YAML + + - hosts: all + + roles: + - pgkehle.proxy-setup +``` + +## License + +MIT + +## Author Information + +Paul Kehle +@pgkehle ([twitter](https://twitter.com/pgkehle), [github](https://github.com/pgkehle), [linkedin](https://www.linkedin.com/in/pgkehle)) + +### References + +* http://digitaldrummerj.me/proxy-configurations/ +* http://askubuntu.com/questions/664777/systemwide-proxy-settings-in-ubuntu diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..cd21505 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..50f63ad --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,13 @@ +galaxy_info: + author: Paul Kehle + description: Configure packages to use a Proxy Server + company: pgkehle + license: MIT + min_ansible_version: 1.9 + platforms: + - name: Ubuntu + versions: + - xenial + galaxy_tags: + - system +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..1ef845f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,88 @@ +--- + + - set_fact: + b1: [] + b2: [] + b3: [] + + # + # /etc/environment + # + - name: Create the environment block + set_fact: + b1: "{{ b1 }} + ['{{ item }}=http://{{ proxy_addr }}:{{ proxy_port }}/']" + with_items: + - http_proxy + - https_proxy + - ftp_proxy + - HTTP_PROXY + - HTTPS_PROXY + - FTP_PROXY + + - name: Append to the environment block + set_fact: + b1: "{{ b1 }} + ['{{ item }}=\"localhost,127.0.0.1,localaddress,.localdomain.com\"']" + with_items: + - no_proxy + - NO_PROXY + + - name: Update /etc/environment + blockinfile: + dest: /etc/environment + block: "{{ b1 | join('\n') }}" + insertafter: EOF + become: true + + # + # /etc/profile.d/proxy.sh + # + + - name: Create the profile block + set_fact: + b2: "{{ b2 }} + ['export {{ item.opt }}={{ item.prot }}://{{ proxy_addr }}:{{ proxy_port }}/']" + with_items: + - {opt: http_proxy, prot: http} + - {opt: https_proxy, prot: http} + - {opt: ftp_proxy, prot: http} + - {opt: socks_proxy,prot: socks} + - {opt: npm_config_proxy, prot: http} + - {opt: npm_config_https_proxy, prot: http} + + - name: Update /etc/profile.d/proxy.sh + blockinfile: + dest: /etc/profile.d/proxy.sh + block: "{{ b2 | join('\n') }}" + insertafter: EOF + become: true + + # + # /etc/apt/apt.conf.d/80proxy + # + + - name: Create the apt.conf block + set_fact: + b3: "{{ b3 }} + ['{{ item }};']" + with_items: + - Acquire::http::proxy "http://{{ proxy_addr }}:{{ proxy_port }}/" + - Acquire::ftp::proxy "ftp://{{ proxy_addr }}:{{ proxy_port }}/" + - Acquire::https::proxy "https://{{ proxy_addr }}:{{ proxy_port }}/" + + - name: Update /etc/apt/apt.conf.d/80proxy + blockinfile: + dest: /etc/apt/apt.conf.d/80proxy + block: "{{ b3 | join('\n') }}" + insertafter: EOF + become: true + + # + # git + # + + - name: Add proxy to git + shell: git config --global {{ item.opt }} {{ item.prot }}://{{ proxy_addr }}:{{ proxy_port }} + with_items: + - { opt: http.proxy, prot: http } + - { opt: https.proxy, prot: https } + + - name: Set git to https + shell: git config --global url."https://github.com/".insteadOf git://github.com/ diff --git a/templates/.keep b/templates/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vars/main.yaml b/vars/main.yaml new file mode 100644 index 0000000..cd21505 --- /dev/null +++ b/vars/main.yaml @@ -0,0 +1,2 @@ +--- + From 6c04b5f03cd155bed6aa33c43302a2ec0ee595eb Mon Sep 17 00:00:00 2001 From: Paul Kehle Date: Tue, 22 Nov 2016 09:58:28 -0500 Subject: [PATCH 2/2] updated marker to separate some common blockinfile tasks from other playbooks/roles --- README.md | 1 + tasks/main.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 0def449..f9e4a04 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,4 @@ Paul Kehle * http://digitaldrummerj.me/proxy-configurations/ * http://askubuntu.com/questions/664777/systemwide-proxy-settings-in-ubuntu +* http://www.linuxsecrets.com/blog/6managing-linux-systems/2015/05/26/1490-manually-change-ubuntu-proxy-settings-from-cli-command-line-terminal diff --git a/tasks/main.yml b/tasks/main.yml index 1ef845f..a46a505 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -31,6 +31,7 @@ dest: /etc/environment block: "{{ b1 | join('\n') }}" insertafter: EOF + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" become: true # @@ -53,6 +54,7 @@ dest: /etc/profile.d/proxy.sh block: "{{ b2 | join('\n') }}" insertafter: EOF + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" become: true # @@ -72,6 +74,7 @@ dest: /etc/apt/apt.conf.d/80proxy block: "{{ b3 | join('\n') }}" insertafter: EOF + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" become: true #