Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.yaml linguist-language=Ruby
*.yml linguist-language=Ruby
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---

13 changes: 13 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
galaxy_info:
author: Paul Kehle <twitter.com/pgkehle>
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: []
91 changes: 91 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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/
Empty file added templates/.keep
Empty file.
2 changes: 2 additions & 0 deletions vars/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---