feat: add proxy url

This commit is contained in:
Adrien Waksberg 2022-04-04 16:43:16 +02:00
parent e870e0971c
commit 3b397ff4b2
6 changed files with 36 additions and 0 deletions

View file

@ -55,6 +55,14 @@ Install and configure Telegraf
files: ['stdout', '/tmp/metrics.out']
```
* `telegraf_proxy_url` - set a proxy url for http and https requests
* `telegraf_proxy_ignore` - array with ignore host or subnet
```
- localhost
- 10.0.0.0/8
```
## How to use
```

View file

@ -15,3 +15,4 @@ telegraf_config: {}
telegraf_full_config: '{{ telegraf_default_config|combine(telegraf_config) }}'
telegraf_inputs: {}
telegraf_outputs: {}
telegraf_proxy_ignore: []

View file

@ -13,6 +13,7 @@
totalcpu: true
collect_cpu_time: false
report_active: false
telegraf_proxy_url: http://127.0.0.1:3128
pre_tasks:
- name: update apt cache

View file

@ -14,6 +14,15 @@ def test_config_file(host):
assert path.mode == 0o640
assert path.contains('files = \\["stdout", "/tmp/metrics.out"\\]')
def test_config_file(host):
path = host.file('/etc/default/telegraf')
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('telegraf')
assert service.is_running

View file

@ -23,6 +23,16 @@
- telegraf
tags: telegraf
- name: copy default variables file
ansible.builtin.template:
src: default.j2
dest: /etc/default/telegraf
owner: root
group: root
mode: 0644
notify: restart telegraf
tags: telegraf
- name: copy config file
ansible.builtin.template:
src: telegraf.conf.j2

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 %}