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..f9e4a04 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ -# 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 +* 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/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..a46a505 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,91 @@ +--- + + - 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 + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" + 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 + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" + 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 + marker: "# {mark} ANSIBLE MANAGED BLOCK - PROXY" + 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 @@ +--- +