feat: add proxy env variables

This commit is contained in:
Adrien Waksberg 2022-04-06 10:17:32 +02:00
parent a505958ba8
commit ca71040514
6 changed files with 40 additions and 0 deletions

View file

@ -61,6 +61,14 @@ gitlab:
user: www-data
```
* `swarm_proxy_url` - set a proxy url for http and https requests
* `swarm_proxy_ignore` - array with ignore host or subnet
```
- localhost
- 10.0.0.0/8
```
## How to use
* Install:

5
handlers/main.yml Normal file
View file

@ -0,0 +1,5 @@
---
- name: restart docker
ansible.builtin.service:
name: docker
state: restarted

View file

@ -4,6 +4,7 @@
roles:
- swarm
vars:
swarm_proxy_url: http://127.0.0.1:3128
swarm_manager: true
swarm_init: true
swarm_networks:

View file

@ -7,6 +7,15 @@ def test_packages(host):
package = host.package('docker.io')
assert package.is_installed
def test_default_config_file(host):
path = host.file('/etc/default/docker')
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('https_proxy=http://127.0.0.1:3128')
def test_service(host):
service = host.service('docker')
assert service.is_running

View file

@ -6,6 +6,16 @@
- python3-docker
tags: swarm
- name: copy default variables file
ansible.builtin.template:
src: default.j2
dest: /etc/default/docker
owner: root
group: root
mode: 0644
notify: restart docker
tags: swarm
- name: enable and start service
ansible.builtin.service:
name: docker

7
templates/default.j2 Normal file
View file

@ -0,0 +1,7 @@
# {{ ansible_managed }}
{% if telegraf_proxy_url is defined %}
https_proxy={{ telegraf_proxy_url }}
http_proxy={{ telegraf_proxy_url }}
no_proxy={{ telegraf_proxy_ignore|join(',') }}
{% endif %}