Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
102c636144 | |||
c47ba8133f | |||
09efb3115a | |||
a3138ac6ec | |||
b865f21bcf | |||
a7168840b0 | |||
4b97f2fea3 | |||
4426dbe53f | |||
123b83c869 | |||
3b397ff4b2 | |||
e870e0971c |
14 changed files with 161 additions and 44 deletions
18
.forgejo/workflows/molecule.yml
Normal file
18
.forgejo/workflows/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
on: [push]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.waks.be/nishiki/molecule:docker
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: ansible-lint .
|
||||
- run: yamllint .
|
||||
molecule:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.waks.be/nishiki/molecule:docker
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: molecule test
|
10
.gitlab-ci.yml
Normal file
10
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
image: nishiki/molecule:docker
|
||||
|
||||
before_script:
|
||||
- molecule --version
|
||||
|
||||
molecule:
|
||||
stage: test
|
||||
script:
|
||||
- molecule test
|
|
@ -2,11 +2,11 @@
|
|||
extends: default
|
||||
|
||||
ignore: |
|
||||
.kitchen/*
|
||||
.kitchen*
|
||||
vendor/
|
||||
.forgejo/
|
||||
|
||||
rules:
|
||||
line-length:
|
||||
max: 120
|
||||
level: warning
|
||||
truthy: false
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -5,6 +5,22 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- add submode for inputs
|
||||
|
||||
### Changed
|
||||
|
||||
- test: use personal docker registry
|
||||
|
||||
### Fixed
|
||||
|
||||
- change apt key
|
||||
|
||||
### Removed
|
||||
|
||||
- support debian 11
|
||||
|
||||
## v1.0.0 - 2021-08-20
|
||||
|
||||
### Added
|
||||
|
|
49
README.md
49
README.md
|
@ -1,20 +1,20 @@
|
|||
# Ansible role: Telegraf
|
||||
|
||||
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-telegraf/releases)
|
||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-telegraf/src/branch/master/LICENSE)
|
||||
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://code.waks.be/nishiki/ansible-role-telegraf/releases)
|
||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://code.waks.be/nishiki/ansible-role-telegraf/src/branch/main/LICENSE)
|
||||
[![Build](https://code.waks.be/nishiki/ansible-role-telegraf/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-telegraf/actions?workflow=molecule.yml)
|
||||
|
||||
Install and configure Telegraf
|
||||
|
||||
## Requirements
|
||||
|
||||
* Ansible >= 2.9
|
||||
* Debian
|
||||
* Buster
|
||||
* Bullseye
|
||||
- Ansible >= 2.9
|
||||
- Debian
|
||||
- Bookworm
|
||||
|
||||
## Role variables
|
||||
|
||||
* `telegraf_config` - hash with the general configuration (see [telegraf documentation](https://docs.influxdata.com/telegraf/latest/administration/configuration/))
|
||||
- `telegraf_config` - hash with the general configuration (see [telegraf documentation](https://docs.influxdata.com/telegraf/latest/administration/configuration/))
|
||||
|
||||
```
|
||||
agent:
|
||||
|
@ -30,7 +30,7 @@ Install and configure Telegraf
|
|||
omit_hostname: false
|
||||
```
|
||||
|
||||
* `telegraf_inputs` - hash with inputs configuration
|
||||
- `telegraf_inputs` - hash with inputs configuration
|
||||
|
||||
```
|
||||
cpu:
|
||||
|
@ -38,15 +38,38 @@ Install and configure Telegraf
|
|||
totalcpu: true
|
||||
collect_cpu_time: false
|
||||
report_active: false
|
||||
postgresql_extensible:
|
||||
address: "host=localhost"
|
||||
submodule:
|
||||
- name: query
|
||||
version = 901
|
||||
sqlquery = "SELECT pg_is_in_recovery()::INT"
|
||||
withdbname = false
|
||||
tagvalue = ""
|
||||
```
|
||||
|
||||
* `telegraf_outputs` - hash with outputs configuration
|
||||
- `telegraf_outputs` - hash with outputs configuration
|
||||
|
||||
```
|
||||
file:
|
||||
files: ['stdout', '/tmp/metrics.out']
|
||||
```
|
||||
|
||||
- `telegraf_user_groups` - array with the telegraf unix groups
|
||||
|
||||
```
|
||||
- docker
|
||||
- admin
|
||||
```
|
||||
|
||||
- `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
|
||||
|
||||
```
|
||||
|
@ -59,10 +82,10 @@ Install and configure Telegraf
|
|||
|
||||
### Test with molecule and docker
|
||||
|
||||
* install [docker](https://docs.docker.com/engine/installation/)
|
||||
* install `python3` and `python3-pip`
|
||||
* install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint`
|
||||
* run `molecule test`
|
||||
- install [docker](https://docs.docker.com/engine/installation/)
|
||||
- install `python3` and `python3-pip`
|
||||
- install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint`
|
||||
- run `molecule test`
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@ telegraf_default_config:
|
|||
collection_jitter: 0s
|
||||
flush_interval: 10s
|
||||
flush_jitter: 0s
|
||||
precision: ''
|
||||
hostname: ''
|
||||
precision: ""
|
||||
hostname: ""
|
||||
omit_hostname: false
|
||||
telegraf_config: {}
|
||||
telegraf_full_config: '{{ telegraf_default_config|combine(telegraf_config) }}'
|
||||
telegraf_full_config: "{{ telegraf_default_config | combine(telegraf_config) }}"
|
||||
telegraf_inputs: {}
|
||||
telegraf_outputs: {}
|
||||
telegraf_proxy_ignore: []
|
||||
telegraf_user_groups: []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
- name: restart telegraf
|
||||
- name: Restart telegraf
|
||||
ansible.builtin.service:
|
||||
name: telegraf
|
||||
state: restarted
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
---
|
||||
galaxy_info:
|
||||
role_name: telegraf
|
||||
namespace: nishiki
|
||||
author: Adrien Waksberg
|
||||
company: Adrien Waksberg
|
||||
description: Install and configure Telegraf
|
||||
license: Apache2
|
||||
min_ansible_version: 2.9
|
||||
min_ansible_version: "2.9"
|
||||
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- buster
|
||||
- bullseye
|
||||
- bookworm
|
||||
|
||||
galaxy_tags:
|
||||
- metrics
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
vars:
|
||||
telegraf_outputs:
|
||||
file:
|
||||
files: ['stdout', '/tmp/metrics.out']
|
||||
files: ["stdout", "/tmp/metrics.out"]
|
||||
telegraf_inputs:
|
||||
cpu:
|
||||
percpu: true
|
||||
totalcpu: true
|
||||
collect_cpu_time: false
|
||||
report_active: false
|
||||
telegraf_proxy_url: http://127.0.0.1:3128
|
||||
|
||||
pre_tasks:
|
||||
- name: update apt cache
|
||||
|
|
|
@ -2,19 +2,12 @@
|
|||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: debian10
|
||||
image: nishiki/debian10:molecule
|
||||
- name: debian12
|
||||
image: code.waks.be/nishiki/molecule:debian12
|
||||
privileged: true
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
command: /bin/systemd
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
- name: debian11
|
||||
image: nishiki/debian11:molecule
|
||||
privileged: true
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
command: /bin/systemd
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,39 +1,63 @@
|
|||
---
|
||||
- name: install depencies packages
|
||||
- name: Install depencies packages
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- apt-transport-https
|
||||
- gpg
|
||||
tags: telegraf
|
||||
|
||||
- name: add key for influx repository
|
||||
ansible.builtin.apt_key:
|
||||
url: https://repos.influxdata.com/influxdb.key
|
||||
- name: Add repository key
|
||||
ansible.builtin.get_url:
|
||||
url: https://repos.influxdata.com/influxdata-archive_compat.key
|
||||
dest: /etc/apt/keyrings/influx.asc
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
checksum: sha256:393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c
|
||||
tags: telegraf
|
||||
|
||||
- name: add influx repository
|
||||
- name: Add repository
|
||||
ansible.builtin.apt_repository:
|
||||
repo: >
|
||||
deb [signed-by=/etc/apt/keyrings/influx.asc]
|
||||
https://repos.influxdata.com/debian stable main
|
||||
filename: influx
|
||||
repo: 'deb https://repos.influxdata.com/debian {{ ansible_distribution_release }} stable'
|
||||
tags: telegraf
|
||||
|
||||
- name: install influxdb package
|
||||
- name: Install influxdb package
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- telegraf
|
||||
tags: telegraf
|
||||
|
||||
- name: copy config file
|
||||
- name: Add groups for telegraf user
|
||||
ansible.builtin.user:
|
||||
name: telegraf
|
||||
groups: "{{ telegraf_user_groups }}"
|
||||
notify: Restart 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
|
||||
dest: /etc/telegraf/telegraf.conf
|
||||
owner: root
|
||||
group: telegraf
|
||||
mode: 0640
|
||||
notify: restart telegraf
|
||||
notify: Restart telegraf
|
||||
tags: telegraf
|
||||
|
||||
- name: start and enable service
|
||||
- name: Start and enable service
|
||||
ansible.builtin.service:
|
||||
name: telegraf
|
||||
state: started
|
||||
|
|
7
templates/default.j2
Normal file
7
templates/default.j2
Normal 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 %}
|
|
@ -27,11 +27,25 @@
|
|||
|
||||
[[inputs.{{ input }}]]
|
||||
{% for option, value in options.items() %}
|
||||
{% if option != 'submodule' %}
|
||||
{{ option }} = {% if value is sameas true %}true
|
||||
{% elif value is sameas false %}false
|
||||
{% elif value is string %}"{{ value }}"
|
||||
{% elif value is number %}{{ value }}
|
||||
{% else %}["{{ value|join('", "') }}"]
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% for submod in value %}
|
||||
[[inputs.{{ input }}.{{ submod.name }} ]]
|
||||
{% for opt, val in submod.config.items() %}
|
||||
{{ opt }} = {% if val is sameas true %}true
|
||||
{% elif val is sameas false %}false
|
||||
{% elif val is string %}"{{ val }}"
|
||||
{% elif val is number %}{{ val }}
|
||||
{% else %}["{{ val|join('", "') }}"]
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue