Skip to content

Commit ff67030

Browse files
committed
add ansible example
- support for auto install proxy config to many hosts
1 parent 2456b35 commit ff67030

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

Diff for: docs/ansible/readme.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Add to you playbook.yml
2+
3+
```yaml
4+
- hosts: docker
5+
gather_facts: yes
6+
become: yes
7+
become_method: sudo
8+
vars:
9+
docker_proxy_url: 192.168.66.72 #you proxy url
10+
roles:
11+
- role: docker-proxy
12+
```

Diff for: docs/ansible/roles/docker-proxy/defaults/vars.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker_proxy_url: 192.168.66.72

Diff for: docs/ansible/roles/docker-proxy/tasks/centos.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: Get the CA certificate from the proxy and make it a trusted root.
2+
get_url:
3+
url: http://{{ docker_proxy_url }}:3128/ca.crt
4+
dest: /etc/pki/ca-trust/source/anchors/docker_registry_proxy.crt
5+
mode: '0644'
6+
- name: update trusted ca redhat
7+
shell: /bin/update-ca-trust

Diff for: docs/ansible/roles/docker-proxy/tasks/main.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Ensures docker.service.d dir exists
3+
file: >
4+
path=/etc/systemd/system/docker.service.d
5+
recurse=yes
6+
state=directory
7+
- name: Add environment vars pointing Docker to use the proxy
8+
copy:
9+
dest: /etc/systemd/system/docker.service.d/http-proxy.conf
10+
content: |
11+
[Service]
12+
Environment="HTTP_PROXY=http://{{ docker_proxy_url }}:3128/"
13+
Environment="HTTPS_PROXY=http://{{ docker_proxy_url }}:3128/"
14+
15+
- name: Include ubuntu tasks
16+
include_tasks: ubuntu.yml
17+
when: ansible_os_family == "Debian"
18+
19+
- name: Include centos tasks
20+
include_tasks: centos.yml
21+
when: ansible_os_family == "RedHat"
22+
23+
- name: Just force systemd to reread configs (2.4 and above)
24+
ansible.builtin.systemd:
25+
daemon_reload: yes
26+
27+
- name: Reload service docker, in all cases
28+
ansible.builtin.systemd:
29+
name: docker.service
30+
state: reloaded

Diff for: docs/ansible/roles/docker-proxy/tasks/ubuntu.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- name: Get the CA certificate from the proxy and make it a trusted root.
2+
get_url:
3+
url: http://{{ docker_proxy_url }}:3128/ca.crt
4+
dest: /usr/share/ca-certificates/docker_registry_proxy.crt
5+
mode: '0644'
6+
7+
- name: update trusted ca
8+
shell: /usr/sbin/update-ca-certificates --fresh

0 commit comments

Comments
 (0)