Skip to content

add ansible example #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions docs/ansible/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Add to you playbook.yml

```yaml
- hosts: docker
gather_facts: yes
become: yes
become_method: sudo
vars:
docker_proxy_url: 192.168.66.72 #you proxy url
roles:
- role: docker-proxy
```
1 change: 1 addition & 0 deletions docs/ansible/roles/docker-proxy/defaults/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker_proxy_url: 192.168.66.72
7 changes: 7 additions & 0 deletions docs/ansible/roles/docker-proxy/tasks/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Get the CA certificate from the proxy and make it a trusted root.
get_url:
url: http://{{ docker_proxy_url }}:3128/ca.crt
dest: /etc/pki/ca-trust/source/anchors/docker_registry_proxy.crt
mode: '0644'
- name: update trusted ca redhat
shell: /bin/update-ca-trust
30 changes: 30 additions & 0 deletions docs/ansible/roles/docker-proxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Ensures docker.service.d dir exists
file: >
path=/etc/systemd/system/docker.service.d
recurse=yes
state=directory
- name: Add environment vars pointing Docker to use the proxy
copy:
dest: /etc/systemd/system/docker.service.d/http-proxy.conf
content: |
[Service]
Environment="HTTP_PROXY=http://{{ docker_proxy_url }}:3128/"
Environment="HTTPS_PROXY=http://{{ docker_proxy_url }}:3128/"

- name: Include ubuntu tasks
include_tasks: ubuntu.yml
when: ansible_os_family == "Debian"

- name: Include centos tasks
include_tasks: centos.yml
when: ansible_os_family == "RedHat"

- name: Just force systemd to reread configs (2.4 and above)
ansible.builtin.systemd:
daemon_reload: yes

- name: Reload service docker, in all cases
ansible.builtin.systemd:
name: docker.service
state: reloaded
8 changes: 8 additions & 0 deletions docs/ansible/roles/docker-proxy/tasks/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Get the CA certificate from the proxy and make it a trusted root.
get_url:
url: http://{{ docker_proxy_url }}:3128/ca.crt
dest: /usr/share/ca-certificates/docker_registry_proxy.crt
mode: '0644'

- name: update trusted ca
shell: /usr/sbin/update-ca-certificates --fresh