mirror of
https://github.com/dj-wasabi/ansible-telegraf.git
synced 2025-07-17 08:46:37 +00:00
Compare commits
64 Commits
Author | SHA1 | Date | |
---|---|---|---|
7f00767dc2 | |||
04935c3de4 | |||
23f8339d99 | |||
9b912d8f97 | |||
07a0358410 | |||
0b749fba5e | |||
559081b000 | |||
562a751990 | |||
0ad660efb8 | |||
bffd2f1549 | |||
998ad25059 | |||
a5dc1b8de5 | |||
bc3b670ca2 | |||
add696bc78 | |||
1112020f45 | |||
6e72a8f278 | |||
7508f3927d | |||
79422a70a1 | |||
d3195b7b88 | |||
20a7653f95 | |||
08b1c62710 | |||
4b10834a00 | |||
9353a544f9 | |||
d750f4d259 | |||
7c32a52748 | |||
7a1ae28929 | |||
59b3613fe1 | |||
987aeb4406 | |||
b15e674884 | |||
331ffb7cb5 | |||
ea64e9bac4 | |||
292cc2a2f4 | |||
685487f198 | |||
7b8809c311 | |||
8fdab6fdcd | |||
7d5d5c1ea1 | |||
7d89ab270a | |||
4956663701 | |||
67253f5438 | |||
a55ef0b0c0 | |||
0006d91e5e | |||
10193da1cf | |||
a4c6db7be1 | |||
02d6e48a39 | |||
e977863e97 | |||
a1505ad499 | |||
a4cf4827cc | |||
b48ff6b273 | |||
2687513dc8 | |||
341a00f16d | |||
4b6f773bba | |||
ff9a820b01 | |||
dec1cab940 | |||
4fdafac2d0 | |||
0c500cf06d | |||
ab68b6813b | |||
852cfaa55e | |||
3fdba74518 | |||
f843a3f51a | |||
4ab32df6df | |||
ca4a07f87d | |||
3cd91d0316 | |||
27f2665772 | |||
a11694ff86 |
4
.github/FUNDING.yml
vendored
Normal file
4
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: dj-wasabi
|
||||
patreon: wernerdijkerman
|
65
.github/workflows/telegraf.yml
vendored
Normal file
65
.github/workflows/telegraf.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
name: "ansible-telegraf"
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'defaults/**'
|
||||
- 'files/**'
|
||||
- 'handlers/**'
|
||||
- 'meta/**'
|
||||
- 'molecule/**'
|
||||
- 'tasks/**'
|
||||
- 'templates/**'
|
||||
- '.github/workflows/telegraf.yml'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'defaults/**'
|
||||
- 'files/**'
|
||||
- 'handlers/**'
|
||||
- 'meta/**'
|
||||
- 'molecule/**'
|
||||
- 'tasks/**'
|
||||
- 'templates/**'
|
||||
- '.github/workflows/telegraf.yml'
|
||||
jobs:
|
||||
molecule:
|
||||
runs-on: ubuntu-18.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
molecule_distro:
|
||||
- container: centos8
|
||||
image: geerlingguy/docker-centos8-ansible:latest
|
||||
- container: centos7
|
||||
image: geerlingguy/docker-centos7-ansible:latest
|
||||
- container: ubuntu2004
|
||||
image: geerlingguy/docker-ubuntu2004-ansible:latest
|
||||
- container: ubuntu1804
|
||||
image: geerlingguy/docker-ubuntu1804-ansible:latest
|
||||
- container: ubuntu1604
|
||||
image: geerlingguy/docker-ubuntu1604-ansible:latest
|
||||
- container: debian9
|
||||
image: geerlingguy/docker-debian9-ansible:latest
|
||||
- container: debian8
|
||||
image: geerlingguy/docker-debian8-ansible:latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Set up Python 3.7
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.7
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
curl -so requirements.txt 'https://raw.githubusercontent.com/dj-wasabi/dj-wasabi-release/main/requirements.txt'
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Run role tests
|
||||
run: >-
|
||||
MY_MOLECULE_CONTAINER=${{ matrix.molecule_distro.container }}
|
||||
MY_MOLECULE_IMAGE=${{ matrix.molecule_distro.image }}
|
||||
MY_MOLECULE_GROUP=${{ matrix.molecule_distro.group }}
|
||||
MY_MOLECULE_DOCKER_COMMAND=${{ matrix.molecule_distro.command }}
|
||||
molecule test
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,3 +5,5 @@ tests/.cache
|
||||
__pycache__
|
||||
*.retry
|
||||
pmip
|
||||
# IDE:s
|
||||
.idea
|
||||
|
11
.pre-commit-config.yaml
Normal file
11
.pre-commit-config.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
repos:
|
||||
# - repo: https://github.com/dj-wasabi/pre-commit-hooks
|
||||
# rev: master
|
||||
# hooks:
|
||||
# - id: ansible-lint
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.2.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
16
.travis.yml
16
.travis.yml
@ -1,16 +0,0 @@
|
||||
---
|
||||
sudo: required
|
||||
language: python
|
||||
services:
|
||||
- docker
|
||||
|
||||
install:
|
||||
- curl -sSlo requirements.txt https://raw.githubusercontent.com/dj-wasabi/ansible-ci-base/master/requirements.txt
|
||||
- pip install -r requirements.txt
|
||||
|
||||
script:
|
||||
- molecule --version
|
||||
- ansible --version
|
||||
- molecule test
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -5,6 +5,19 @@ Below an overview of all changes in the releases.
|
||||
|
||||
Version (Release date)
|
||||
|
||||
0.12.0 (2019-03-12)
|
||||
|
||||
* Download from influxdb #109
|
||||
* Don't override package name unless "latest" #108 (By pull request: matttrach (Thanks!))
|
||||
* Adding support for arm64 systems #106 (By pull request: remkade (Thanks!))
|
||||
* Use items() instead of iteritems() #104 (By pull request: diego1q2w
|
||||
* Fix: ensure apt-cache is updated before install #103 (By pull request: asfaltboy (Thanks!))
|
||||
* on FreeBSD the telegeraf.conf is in root of /usr/local/etc. #102 (By pull request: langerma (Thanks!))
|
||||
* Some changes for fixing FreeBSD #101
|
||||
* basic FreeBSD support #100 (By pull request: langerma (Thanks!))
|
||||
* Added the use_proxy argument to use a proxy (or not) #98
|
||||
* Various small changes for molecule #97
|
||||
|
||||
0.12.0 (2019-03-12)
|
||||
|
||||
* Add support for extra win_perf_counters and prevent python u'' strings #76 (By pull request: jdivy (Thanks!))
|
||||
|
90
README.md
90
README.md
@ -1,8 +1,39 @@
|
||||
# dj-wasabi.telegraf
|
||||
|
||||
- [dj-wasabi.telegraf](#dj-wasabitelegraf)
|
||||
* [Build status:](#build-status-)
|
||||
* [Requirements](#requirements)
|
||||
+ [Supported systems](#supported-systems)
|
||||
+ [InfluxDB](#influxdb)
|
||||
+ [Docker](#docker)
|
||||
* [Upgrade](#upgrade)
|
||||
+ [0.7.0](#070)
|
||||
* [Role Variables](#role-variables)
|
||||
+ [Ansible role specific variables](#ansible-role-specific-variables)
|
||||
- [Telegraf Package](#telegraf-package)
|
||||
+ [Telegraf agent process configuration.](#telegraf-agent-process-configuration)
|
||||
+ [Docker specific role variables:](#docker-specific-role-variables-)
|
||||
* [Extra information](#extra-information)
|
||||
+ [ansible_fqdn problematic for getting hostname](#ansible-fqdn-problematic-for-getting-hostname)
|
||||
+ [Setting tags](#setting-tags)
|
||||
+ [Docker specifics](#docker-specifics)
|
||||
- [Docker image](#docker-image)
|
||||
- [Docker mounts](#docker-mounts)
|
||||
- [Example Docker configuration](#example-docker-configuration)
|
||||
* [Windows specific Variables](#windows-specific-variables)
|
||||
* [Extra information](#extra-information-1)
|
||||
+ [telegraf_plugins_default](#telegraf-plugins-default)
|
||||
+ [telegraf_plugins_extra](#telegraf-plugins-extra)
|
||||
* [Dependencies](#dependencies)
|
||||
* [Example Playbook](#example-playbook)
|
||||
* [Contributors](#contributors)
|
||||
* [Molecule](#molecule)
|
||||
* [License](#license)
|
||||
* [Author Information](#author-information)
|
||||
|
||||
## Build status:
|
||||
|
||||
[](https://travis-ci.org/dj-wasabi/ansible-telegraf)
|
||||
[](https://actions-badge.atrox.dev/dj-wasabi/ansible-telegraf/goto?ref=master) <img src="https://img.shields.io/ansible/role/d/5173"/> <img src="https://img.shields.io/ansible/quality/5173"/>
|
||||
|
||||
This role will install and configure telegraf.
|
||||
|
||||
@ -15,14 +46,16 @@ Design goals are to have a minimal memory footprint with a plugin system so that
|
||||
## Requirements
|
||||
|
||||
### Supported systems
|
||||
|
||||
This role supports the following systems:
|
||||
|
||||
* Red Hat
|
||||
* Debian
|
||||
* Ubuntu
|
||||
* Docker container
|
||||
* Windows (Best effort)
|
||||
* (Open)Suse
|
||||
* Windows (Best effort)
|
||||
* FreeBSD (Best effort)
|
||||
|
||||
So, you'll need one of those systems.. :-)
|
||||
Please sent Pull Requests or suggestions when you want to use this role for other systems.
|
||||
@ -55,13 +88,14 @@ Specifying the version to be installed:
|
||||
|
||||
* `telegraf_agent_version`: The version of Telegraf to install. Default: `1.10.0`
|
||||
|
||||
How `Telegraf` needs to be installed. There are 3 methods in getting `Telegraf` installed on the target host:
|
||||
How `Telegraf` needs to be installed. There are 4 methods in getting `Telegraf` installed on the target host:
|
||||
|
||||
* Via the package manager, like `yum`, `apt` or `zypper` ("repo");
|
||||
* Via a download from the `https://dl.influxdata.com/` site ("online");
|
||||
* Already provided and is already available on the target host, but not yet installed/configured ("offline");
|
||||
* Already installed on the target host or done manually, but not yet configured ("manual");
|
||||
|
||||
This can be configured by setting `telegraf_agent_package_method` to one of the appropriate values ( `repo`, `online` or `offline`).
|
||||
This can be configured by setting `telegraf_agent_package_method` to one of the appropriate values ( `repo`, `online`, `offline` or `manual`).
|
||||
|
||||
#### Telegraf Package
|
||||
|
||||
@ -99,6 +133,23 @@ These properties set in how and what package will be installed.
|
||||
Full agent settings reference: [https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#agent-configuration](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#agent-configuration).
|
||||
|
||||
## Extra information
|
||||
|
||||
### ansible_fqdn problematic for getting hostname
|
||||
|
||||
Extra info regarding: ansible_fqdn problematic for getting hostname #105
|
||||
|
||||
*Describe the bug*
|
||||
|
||||
In some nodes I'm getting weird hostnames, mostly localhost.localdomain. Those nodes show proper configuration in hostnamectl. I've seen you're using 'ansible_fqdn' as default.
|
||||
|
||||
Seems like ansible_fqdn and ansible_hostname can give different results, and sometimes even very weird results, as it sometimes makes DNS calls (which is not under my control in that cases) to infer that names.
|
||||
|
||||
*Fix proposal*
|
||||
|
||||
In my playbook I've added this parameter:
|
||||
|
||||
telegraf_agent_hostname: "{{ ansible_nodename }}"
|
||||
|
||||
### Setting tags
|
||||
|
||||
You can set tags for the host running telegraf:
|
||||
@ -154,10 +205,8 @@ More information: [https://github.com/influxdata/telegraf/blob/master/docs/FAQ.m
|
||||
telegraf_plugins_default:
|
||||
- plugin: cpu
|
||||
config:
|
||||
- percpu = "true"
|
||||
- percpu = true
|
||||
- plugin: disk
|
||||
tags:
|
||||
- diskmetrics = "true"
|
||||
tagpass:
|
||||
- fstype = [ "ext4", "xfs" ]
|
||||
tagdrop:
|
||||
@ -183,6 +232,14 @@ _Supporting Windows is an best effort (I don't have the possibility to either te
|
||||
* `telegraf_win_logfile`: The location to the logfile of Telegraf.
|
||||
* `telegraf_win_include`: The directory that will contain all plugin configuration.
|
||||
|
||||
## MacOS specific Variables
|
||||
|
||||
**NOTE**
|
||||
|
||||
_MacOS support is as the Window Support an best effort and not officially supported._
|
||||
|
||||
* `telegraf_mac_user`: Telegraf will run as this user (needed as running things as other users using brew is problematic)
|
||||
|
||||
## Extra information
|
||||
|
||||
There are two properties which are similar, but are used differently. Those are:
|
||||
@ -190,6 +247,8 @@ There are two properties which are similar, but are used differently. Those are:
|
||||
* `telegraf_plugins_default`
|
||||
* `telegraf_plugins_extra`
|
||||
|
||||
### telegraf_plugins_default
|
||||
|
||||
With the property `telegraf_plugins_default` it is set to use the default set of Telegraf plugins. You could override it with more plugins, which should be enabled at default.
|
||||
|
||||
telegraf_plugins_default:
|
||||
@ -205,6 +264,8 @@ With the property `telegraf_plugins_default` it is set to use the default set of
|
||||
|
||||
Every telegraf agent has these as a default configuration.
|
||||
|
||||
### telegraf_plugins_extra
|
||||
|
||||
The 2nd parameter `telegraf_plugins_extra` can be used to add plugins specific to the servers goal. It is a hash instead of a list, so that you can merge values from multiple var files together. Following is an example for using this parameter for MySQL database servers:
|
||||
|
||||
cat group_vars/mysql_database
|
||||
@ -221,6 +282,8 @@ Telegraf plugin options:
|
||||
* `tagpass`: (added in Telegraf 0.1.5) tag names and arrays of strings that are used to filter metrics by the current plugin. Each string in the array is tested as an exact match against the tag name, and if it matches the metric is emitted.
|
||||
* `tagdrop`: (added in Telegraf 0.1.5) The inverse of tagpass. If a tag matches, the metric is not emitted. This is tested on metrics that have passed the tagpass test.
|
||||
* `interval`: How often to gather this metric. Normal plugins use a single global interval, but if one particular plugin should be run less or more often, you can configure that here.
|
||||
* `filter.name`: Like when there is an extra filter that needs to be configured, like `grok` for a `logparser` plugin.
|
||||
* `filter.config`: The extra configuration for the - in the `filter.name` example - `grok` filter. (See example below)
|
||||
|
||||
An example might look like this:
|
||||
|
||||
@ -244,6 +307,19 @@ telegraf_processors:
|
||||
- dest = "LogLevel"
|
||||
```
|
||||
|
||||
When you want to make use of the `grok` filter for the logparser:
|
||||
|
||||
telegraf_plugins_extra:
|
||||
logparser:
|
||||
plugin: logparser
|
||||
config:
|
||||
- files = ["/var/log/messages"]
|
||||
- from_beginning = false
|
||||
filter:
|
||||
name: grok
|
||||
config:
|
||||
- patterns = ["invoked oom-killer"]
|
||||
|
||||
## Dependencies
|
||||
|
||||
No dependencies
|
||||
|
@ -1,9 +1,12 @@
|
||||
---
|
||||
telegraf_enabled: True
|
||||
# defaults file for ansible-telegraf
|
||||
|
||||
telegraf_agent_version: 1.10.0
|
||||
telegraf_agent_version_patch: 1
|
||||
telegraf_agent_package: telegraf
|
||||
telegraf_agent_package_file_deb: telegraf_{{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}_{{ telegraf_agent_package_arch }}.deb
|
||||
telegraf_agent_package_file_rpm: telegraf-{{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}.{{ ansible_architecture }}.rpm
|
||||
telegraf_agent_package_path: /tmp
|
||||
telegraf_agent_package_method: repo
|
||||
telegraf_agent_package_state: present
|
||||
@ -15,6 +18,7 @@ telegraf_agent_flush_interval: 10
|
||||
telegraf_agent_flush_jitter: 0
|
||||
telegraf_agent_aws_tags: False
|
||||
telegraf_agent_aws_tags_prefix: ""
|
||||
telegraf_agent_config_path: /etc/telegraf
|
||||
|
||||
# Docker specific settings
|
||||
telegraf_uid_docker: 998
|
||||
@ -70,6 +74,7 @@ telegraf_yum_baseurl:
|
||||
centos: "https://repos.influxdata.com/rhel/{{ telegraf_redhat_releasever }}/$basearch/stable"
|
||||
default: "https://repos.influxdata.com/{{ ansible_distribution|lower }}/{{ telegraf_redhat_releasever }}/$basearch/stable"
|
||||
redhat: "https://repos.influxdata.com/rhel/{{ telegraf_redhat_releasever }}/$basearch/stable"
|
||||
telegraf_yum_gpgkey: "https://repos.influxdata.com/influxdb.key"
|
||||
|
||||
telegraf_win_install_dir: 'C:\Telegraf'
|
||||
telegraf_win_logfile: 'C:\\Telegraf\\telegraf.log'
|
||||
@ -78,3 +83,6 @@ telegraf_win_service_args:
|
||||
- -service install
|
||||
- -config {{ telegraf_win_install_dir }}\telegraf\telegraf.conf
|
||||
- --config-directory {{ telegraf_win_include }}
|
||||
|
||||
telegraf_mac_user: user
|
||||
telegraf_mac_group: admin
|
||||
|
@ -20,3 +20,6 @@
|
||||
name: Telegraf
|
||||
start_mode: auto
|
||||
state: restarted
|
||||
|
||||
- name: "Restart MacOS Telegraf"
|
||||
shell: brew services restart telegraf
|
||||
|
@ -2,6 +2,7 @@
|
||||
galaxy_info:
|
||||
author: Werner Dijkerman
|
||||
description: Installing and configuring Telegraf
|
||||
role_name: telegraf
|
||||
company: myCompany.Dotcom
|
||||
license: MIT
|
||||
min_ansible_version: 2.4
|
||||
@ -21,6 +22,9 @@ galaxy_info:
|
||||
- name: Windows
|
||||
versions:
|
||||
- all
|
||||
- name: MacOS
|
||||
versions:
|
||||
- all
|
||||
|
||||
galaxy_tags:
|
||||
- monitoring
|
||||
|
@ -1,14 +0,0 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
@ -1,46 +0,0 @@
|
||||
*******
|
||||
Install
|
||||
*******
|
||||
|
||||
This set of playbooks have specific dependencies on Ansible due to the modules
|
||||
being used.
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
* Ansible 2.2
|
||||
* Docker Engine
|
||||
* docker-py
|
||||
|
||||
Install OS dependencies on CentOS 7
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo yum install -y epel-release
|
||||
$ sudo yum install -y gcc python-pip python-devel openssl-devel
|
||||
# If installing Molecule from source.
|
||||
$ sudo yum install libffi-devel git
|
||||
|
||||
Install OS dependencies on Ubuntu 16.x
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install -y python-pip libssl-dev docker-engine
|
||||
# If installing Molecule from source.
|
||||
$ sudo apt-get install -y libffi-dev git
|
||||
|
||||
Install OS dependencies on Mac OS
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ brew install python
|
||||
$ brew install git
|
||||
|
||||
Install using pip:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo pip install ansible
|
||||
$ sudo pip install docker-py
|
||||
$ sudo pip install molecule --pre
|
@ -1,84 +0,0 @@
|
||||
---
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
||||
tasks:
|
||||
- name: Log into a Docker registry
|
||||
docker_login:
|
||||
username: "{{ item.registry.credentials.username }}"
|
||||
password: "{{ item.registry.credentials.password }}"
|
||||
email: "{{ item.registry.credentials.email | default(omit) }}"
|
||||
registry: "{{ item.registry.url }}"
|
||||
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
with_items: "{{ molecule_yml.platforms }}"
|
||||
when:
|
||||
- item.registry is defined
|
||||
- item.registry.credentials is defined
|
||||
- item.registry.credentials.username is defined
|
||||
|
||||
- name: Create Dockerfiles from image names
|
||||
template:
|
||||
src: "{{ molecule_scenario_directory }}/Dockerfile.j2"
|
||||
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
|
||||
with_items: "{{ molecule_yml.platforms }}"
|
||||
register: platforms
|
||||
|
||||
- name: Discover local Docker images
|
||||
docker_image_facts:
|
||||
name: "molecule_local/{{ item.item.name }}"
|
||||
docker_host: "{{ item.item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
with_items: "{{ platforms.results }}"
|
||||
register: docker_images
|
||||
|
||||
- name: Build an Ansible compatible image
|
||||
docker_image:
|
||||
path: "{{ molecule_ephemeral_directory }}"
|
||||
name: "molecule_local/{{ item.item.image }}"
|
||||
docker_host: "{{ item.item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}"
|
||||
force: "{{ item.item.force | default(true) }}"
|
||||
pull: "{{ item.item.pull | default(omit) }}"
|
||||
with_items: "{{ platforms.results }}"
|
||||
when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0
|
||||
|
||||
- name: Create docker network(s)
|
||||
docker_network:
|
||||
name: "{{ item }}"
|
||||
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
state: present
|
||||
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"
|
||||
|
||||
- name: Create molecule instance(s)
|
||||
docker_container:
|
||||
name: "{{ item.name }}"
|
||||
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
hostname: "{{ item.hostname | default(item.name) }}"
|
||||
image: "molecule_local/{{ item.image }}"
|
||||
state: started
|
||||
recreate: false
|
||||
log_driver: json-file
|
||||
command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}"
|
||||
privileged: "{{ item.privileged | default(omit) }}"
|
||||
security_opts: "{{ item.security_opts | default(omit) }}"
|
||||
volumes: "{{ item.volumes | default(omit) }}"
|
||||
tmpfs: "{{ item.tmpfs | default(omit) }}"
|
||||
capabilities: "{{ item.capabilities | default(omit) }}"
|
||||
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
|
||||
published_ports: "{{ item.published_ports | default(omit) }}"
|
||||
ulimits: "{{ item.ulimits | default(omit) }}"
|
||||
networks: "{{ item.networks | default(omit) }}"
|
||||
dns_servers: "{{ item.dns_servers | default(omit) }}"
|
||||
register: server
|
||||
with_items: "{{ molecule_yml.platforms }}"
|
||||
async: 7200
|
||||
poll: 0
|
||||
|
||||
- name: Wait for instance(s) creation to complete
|
||||
async_status:
|
||||
jid: "{{ item.ansible_job_id }}"
|
||||
register: docker_jobs
|
||||
until: docker_jobs.finished
|
||||
retries: 300
|
||||
with_items: "{{ server.results }}"
|
@ -1,32 +0,0 @@
|
||||
---
|
||||
- name: Destroy
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
||||
tasks:
|
||||
- name: Destroy molecule instance(s)
|
||||
docker_container:
|
||||
name: "{{ item.name }}"
|
||||
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
state: absent
|
||||
force_kill: "{{ item.force_kill | default(true) }}"
|
||||
register: server
|
||||
with_items: "{{ molecule_yml.platforms }}"
|
||||
async: 7200
|
||||
poll: 0
|
||||
|
||||
- name: Wait for instance(s) deletion to complete
|
||||
async_status:
|
||||
jid: "{{ item.ansible_job_id }}"
|
||||
register: docker_jobs
|
||||
until: docker_jobs.finished
|
||||
retries: 300
|
||||
with_items: "{{ server.results }}"
|
||||
|
||||
- name: Delete docker network(s)
|
||||
docker_network:
|
||||
name: "{{ item }}"
|
||||
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
|
||||
state: absent
|
||||
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"
|
@ -3,10 +3,6 @@ dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
options:
|
||||
config-file: molecule/default/yaml-lint.yml
|
||||
|
||||
platforms:
|
||||
- name: influxdb
|
||||
@ -18,50 +14,26 @@ platforms:
|
||||
- name: telegraf
|
||||
environment:
|
||||
INFLUXDB_DB: telegraf
|
||||
- name: telegraf-centos
|
||||
image: milcom/centos7-systemd
|
||||
- name: telegraf-${MY_MOLECULE_CONTAINER:-centos8}
|
||||
image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"}
|
||||
command: ${MY_MOLECULE_DOCKER_COMMAND:-""}
|
||||
privileged: True
|
||||
groups:
|
||||
- telegraf
|
||||
pre_build_image: True
|
||||
networks:
|
||||
- name: telegraf
|
||||
- name: telegraf-debian
|
||||
image: minimum2scp/systemd-stretch
|
||||
privileged: True
|
||||
command: /sbin/init
|
||||
groups:
|
||||
- telegraf
|
||||
networks:
|
||||
- name: telegraf
|
||||
- name: telegraf-ubuntu
|
||||
image: solita/ubuntu-systemd:bionic
|
||||
privileged: True
|
||||
command: /sbin/init
|
||||
groups:
|
||||
- telegraf
|
||||
networks:
|
||||
- name: telegraf
|
||||
- name: telegraf-opensuse
|
||||
image: wdijkerman/molecule-systemd-leap
|
||||
privileged: True
|
||||
command: /sbin/init
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
groups:
|
||||
- telegraf
|
||||
networks:
|
||||
- name: telegraf
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
||||
name: ansible-lint
|
||||
inventory:
|
||||
host_vars:
|
||||
telegraf-debian:
|
||||
telegraf_agent_package: /tmp/telegraf_amd64.deb
|
||||
telegraf_agent_package_method: online
|
||||
group_vars:
|
||||
debian:
|
||||
telegraf_agent_package_method: online
|
||||
all:
|
||||
telegraf_agent_package_state: latest
|
||||
telegraf_agent_output:
|
||||
@ -71,13 +43,15 @@ provisioner:
|
||||
- database = "telegraf"
|
||||
- precision = "s"
|
||||
telegraf_plugins_extra:
|
||||
percpu-usage:
|
||||
plugin: cpu
|
||||
logparser:
|
||||
plugin: logparser
|
||||
config:
|
||||
- percpu = true
|
||||
- totalcpu = false
|
||||
- name_override = "percpu_usage"
|
||||
- fielddrop = ["cpu_time*"]
|
||||
- files = ["/var/log/messages"]
|
||||
- from_beginning = false
|
||||
filter:
|
||||
name: grok
|
||||
config:
|
||||
- patterns = ["invoked oom-killer"]
|
||||
|
||||
scenario:
|
||||
name: default
|
||||
|
@ -9,11 +9,22 @@
|
||||
when:
|
||||
- ansible_os_family == 'RedHat'
|
||||
|
||||
- name: "Apt get update"
|
||||
shell: apt-get update && apt-get install -y python-apt
|
||||
when:
|
||||
- ansible_os_family == 'Debian'
|
||||
|
||||
- name: debug
|
||||
debug:
|
||||
var: ansible_distribution_major_version
|
||||
|
||||
- name: "Installing packages on Debian"
|
||||
apt:
|
||||
name:
|
||||
- wget
|
||||
- gpg
|
||||
- python-apt
|
||||
- "{{ 'gnupg-agent' if ansible_distribution_major_version in ['8', '18', '16'] else 'gpg-agent' }}"
|
||||
update_cache: True
|
||||
state: present
|
||||
when:
|
||||
- ansible_os_family == 'Debian'
|
||||
|
@ -6,15 +6,15 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('telegraf')
|
||||
|
||||
|
||||
def test_telegraf_running_and_enabled(Service, SystemInfo):
|
||||
telegraf = Service("telegraf")
|
||||
if SystemInfo.distribution not in ['opensuse-leap']:
|
||||
def test_telegraf_running_and_enabled(host):
|
||||
telegraf = host.service("telegraf")
|
||||
if host.system_info.distribution not in ['opensuse-leap']:
|
||||
assert telegraf.is_enabled
|
||||
assert telegraf.is_running
|
||||
|
||||
|
||||
def test_telegraf_dot_conf(File):
|
||||
telegraf = File("/etc/telegraf/telegraf.conf")
|
||||
def test_telegraf_dot_conf(host):
|
||||
telegraf = host.file("/etc/telegraf/telegraf.conf")
|
||||
assert telegraf.user == "telegraf"
|
||||
assert telegraf.group == "telegraf"
|
||||
assert telegraf.mode == 0o640
|
||||
@ -26,23 +26,23 @@ def test_telegraf_dot_conf(File):
|
||||
assert telegraf.contains('[[inputs.net]]')
|
||||
|
||||
|
||||
def test_telegraf_dot_d_dir(File):
|
||||
telegraf = File("/etc/telegraf/telegraf.d")
|
||||
def test_telegraf_dot_d_dir(host):
|
||||
telegraf = host.file("/etc/telegraf/telegraf.d")
|
||||
assert telegraf.user == "root"
|
||||
assert telegraf.group == "root"
|
||||
assert telegraf.mode == 0o755
|
||||
assert telegraf.is_directory
|
||||
|
||||
|
||||
def test_telegraf_dot_d(File):
|
||||
telegraf = File("/etc/telegraf/telegraf.d/percpu-usage.conf")
|
||||
def test_telegraf_dot_d(host):
|
||||
telegraf = host.file("/etc/telegraf/telegraf.d/logparser.conf")
|
||||
assert telegraf.user == "telegraf"
|
||||
assert telegraf.group == "telegraf"
|
||||
assert telegraf.mode == 0o640
|
||||
assert telegraf.contains('[[inputs.cpu]]')
|
||||
assert telegraf.contains('totalcpu = false')
|
||||
assert telegraf.contains('[[inputs.logparser]]')
|
||||
assert telegraf.contains('from_beginning = false')
|
||||
|
||||
|
||||
def test_telegraf_package(Package):
|
||||
telegraf = Package('telegraf')
|
||||
def test_telegraf_package(host):
|
||||
telegraf = host.package('telegraf')
|
||||
assert telegraf.is_installed
|
||||
|
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
---
|
||||
|
||||
extends: default
|
||||
|
||||
rules:
|
||||
line-length:
|
||||
max: 180
|
||||
level: warning
|
||||
truthy: disable
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
|
||||
- name: "Debian | Set name if state == latest"
|
||||
- name: "Debian | Set name if state != latest"
|
||||
set_fact:
|
||||
telegraf_agent_package: telegraf={{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}
|
||||
when:
|
||||
@ -16,6 +16,12 @@
|
||||
when:
|
||||
- ansible_architecture == "x86_64"
|
||||
|
||||
- name: "Debian | Set telegraf_agent_package_arch specific for arm64"
|
||||
set_fact:
|
||||
telegraf_agent_package_arch: "armhf"
|
||||
when:
|
||||
- ansible_architecture == "arm64"
|
||||
|
||||
- name: "Debian | Ensure the system can use the HTTPS transport for APT"
|
||||
stat:
|
||||
path: /usr/lib/apt/methods/https
|
||||
@ -65,8 +71,12 @@
|
||||
|
||||
- name: "Debian | Download Telegraf package (online)"
|
||||
get_url:
|
||||
url: https://dl.influxdata.com/telegraf/releases/telegraf_{{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}_{{ telegraf_agent_package_arch }}.deb
|
||||
dest: "{{ telegraf_agent_package }}"
|
||||
url: https://dl.influxdata.com/telegraf/releases/{{ telegraf_agent_package_file_deb }}
|
||||
dest: "{{ telegraf_agent_package_path }}/{{ telegraf_agent_package }}"
|
||||
use_proxy: "{{ true if http_proxy is defined and http_proxy else false }}"
|
||||
environment:
|
||||
http_proxy: "{{ http_proxy | default(None) | default(omit) }}"
|
||||
https_proxy: "{{ https_proxy | default(None) | default(omit) }}"
|
||||
when:
|
||||
- telegraf_agent_package_method == "online"
|
||||
|
||||
@ -74,6 +84,7 @@
|
||||
apt:
|
||||
name: "{{ telegraf_agent_package }}"
|
||||
state: "{{ telegraf_agent_package_state }}"
|
||||
update_cache: yes
|
||||
register: is_telegraf_package_installed
|
||||
until: is_telegraf_package_installed is succeeded
|
||||
notify: "Restart Telegraf"
|
||||
@ -83,11 +94,11 @@
|
||||
|
||||
- name: "Debian | Install Telegraf package"
|
||||
apt:
|
||||
deb: "{{ telegraf_agent_package }}"
|
||||
deb: "{{ telegraf_agent_package_path }}/{{ telegraf_agent_package }}"
|
||||
state: "present"
|
||||
register: is_telegraf_package_installed
|
||||
until: is_telegraf_package_installed is succeeded
|
||||
notify: "Restart Telegraf"
|
||||
become: yes
|
||||
when:
|
||||
- telegraf_agent_package_method != "repo"
|
||||
- telegraf_agent_package_method == "online" or telegraf_agent_package_method == "offline"
|
||||
|
24
tasks/FreeBSD.yml
Normal file
24
tasks/FreeBSD.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
# description: FreeBSD specific installation
|
||||
|
||||
- name: "FreeBSD | set package name"
|
||||
set_fact:
|
||||
telegraf_agent_package: telegraf
|
||||
|
||||
- name: "FreeBSD | Install Telegraf package"
|
||||
pkgng:
|
||||
name: "{{ telegraf_agent_package }}"
|
||||
state: "{{ telegraf_agent_package_state }}"
|
||||
register: is_telegraf_package_installed
|
||||
until: is_telegraf_package_installed is succeeded
|
||||
notify: "Restart Telegraf"
|
||||
|
||||
- name: "FreeBSD | add telegraf_flags for extra plugins"
|
||||
shell: sysrc telegraf_flags="-quiet -config-directory=/usr/local/etc/telegraf.d"
|
||||
tags:
|
||||
- skip_ansible_lint
|
||||
|
||||
- name: "FreeBSD | add telegraf to init"
|
||||
shell: sysrc telegraf_enable="YES"
|
||||
tags:
|
||||
- skip_ansible_lint
|
14
tasks/MacOS.yml
Normal file
14
tasks/MacOS.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
# description: MacOS specific installation
|
||||
|
||||
- name: "MacOS | set package name"
|
||||
set_fact:
|
||||
telegraf_agent_package: telegraf
|
||||
|
||||
- name: "MacOS | Install Telegraf package"
|
||||
package:
|
||||
name: "{{ telegraf_agent_package }}"
|
||||
state: "{{ telegraf_agent_package_state }}"
|
||||
register: is_telegraf_package_installed
|
||||
until: is_telegraf_package_installed is succeeded
|
||||
notify: "Restart Telegraf"
|
@ -10,22 +10,28 @@
|
||||
- name: Use RHEL 7 packages for Fedora
|
||||
set_fact:
|
||||
telegraf_redhat_releasever: 7
|
||||
when: ansible_distribution == "Fedora"
|
||||
when:
|
||||
- ansible_distribution == "Fedora"
|
||||
|
||||
- name: "RedHat | Add yum repository"
|
||||
yum_repository:
|
||||
name: influxdb
|
||||
description: InfluxDB Repository - RHEL $releasever
|
||||
baseurl: "{{ telegraf_yum_baseurl[ansible_distribution|lower] | default(telegraf_yum_baseurl['default']) }}"
|
||||
gpgcheck: yes
|
||||
gpgkey: https://repos.influxdata.com/influxdb.key
|
||||
gpgcheck: "{{ telegraf_yum_gpgcheck | default('true') }}"
|
||||
gpgkey: "{{ telegraf_yum_gpgkey }}"
|
||||
become: yes
|
||||
when:
|
||||
- telegraf_agent_package_method == "repo"
|
||||
|
||||
- name: "RedHat | Download Telegraf package (online)"
|
||||
get_url:
|
||||
url: https://dl.influxdata.com/telegraf/releases/telegraf-{{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}.{{ ansible_architecture }}.rpm
|
||||
url: https://dl.influxdata.com/telegraf/releases/{{ telegraf_agent_package_file_rpm }}
|
||||
dest: "{{ telegraf_agent_package }}"
|
||||
use_proxy: "{{ true if http_proxy is defined and http_proxy else false }}"
|
||||
environment:
|
||||
http_proxy: "{{ http_proxy | default(None) | default(omit) }}"
|
||||
https_proxy: "{{ https_proxy | default(None) | default(omit) }}"
|
||||
when:
|
||||
- telegraf_agent_package_method == "online"
|
||||
|
||||
@ -35,4 +41,5 @@
|
||||
state: "{{ telegraf_agent_package_state }}"
|
||||
register: is_telegraf_package_installed
|
||||
until: is_telegraf_package_installed is succeeded
|
||||
become: yes
|
||||
notify: "Restart Telegraf"
|
||||
|
@ -6,6 +6,12 @@
|
||||
when:
|
||||
- telegraf_agent_aws_tags
|
||||
|
||||
- name: "Add prefix path"
|
||||
set_fact:
|
||||
telegraf_agent_config_path: /usr/local/etc
|
||||
when:
|
||||
- ansible_os_family == "FreeBSD"
|
||||
|
||||
- name: Retrieve all ec2 tags on the instance
|
||||
ec2_tag:
|
||||
region: '{{ ansible_ec2_placement_region }}'
|
||||
@ -32,7 +38,7 @@
|
||||
- name: "Copy the template for versions >= 0.10.0"
|
||||
template:
|
||||
src: telegraf.conf.j2
|
||||
dest: /etc/telegraf/telegraf.conf
|
||||
dest: "{{ telegraf_agent_config_path }}/telegraf.conf"
|
||||
owner: telegraf
|
||||
group: telegraf
|
||||
mode: 0640
|
||||
@ -45,7 +51,7 @@
|
||||
|
||||
- name: "Check if extra plugins directory exists in case of exclusive"
|
||||
stat:
|
||||
path: /etc/telegraf/telegraf.d
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d"
|
||||
register: telegraf_directory
|
||||
when:
|
||||
- telegraf_plugins_extra_exclusive
|
||||
@ -53,7 +59,7 @@
|
||||
- name: "Delete telegraf extra plugin path"
|
||||
file:
|
||||
state: absent
|
||||
path: "/etc/telegraf/telegraf.d/"
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||
when:
|
||||
- telegraf_plugins_extra_exclusive
|
||||
- telegraf_directory.stat.exists
|
||||
@ -65,7 +71,7 @@
|
||||
- name: "Create telegraf extra plugin path"
|
||||
file:
|
||||
state: directory
|
||||
path: "/etc/telegraf/telegraf.d/"
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||
owner: telegraf
|
||||
group: telegraf
|
||||
mode: 0755
|
||||
@ -80,7 +86,7 @@
|
||||
- name: "Copy telegraf extra plugins"
|
||||
template:
|
||||
src: "telegraf-extra-plugin.conf.j2"
|
||||
dest: "/etc/telegraf/telegraf.d/{{ item.key }}.conf"
|
||||
dest: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
|
||||
owner: telegraf
|
||||
group: telegraf
|
||||
mode: 0640
|
||||
@ -98,7 +104,7 @@
|
||||
|
||||
- name: "Remove telegraf extra plugins"
|
||||
file:
|
||||
path: "/etc/telegraf/telegraf.d/{{ item.key }}.conf"
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
|
||||
state: absent
|
||||
with_dict: "{{ telegraf_plugins_extra }}"
|
||||
loop_control:
|
||||
@ -118,7 +124,65 @@
|
||||
- name: "Start Telegraf (If it wasn't running)"
|
||||
service:
|
||||
name: telegraf
|
||||
state: started
|
||||
enabled: yes
|
||||
state: "{{ telegraf_enabled | ternary('started', 'stopped') }}"
|
||||
enabled: "{{ telegraf_enabled }}"
|
||||
become: yes
|
||||
when: not telegraf_agent_docker
|
||||
|
||||
- name: Configure system for for docker plugin
|
||||
block:
|
||||
- name: Add telegraf user to docker group
|
||||
user:
|
||||
name: telegraf
|
||||
groups: docker
|
||||
append: true
|
||||
become: true
|
||||
notify:
|
||||
- Restart Telegraf
|
||||
|
||||
when: "'docker' in telegraf_plugins_extra and not telegraf_agent_docker"
|
||||
|
||||
- name: Configure system for for smart plugin
|
||||
block:
|
||||
- name: Install smartmontools
|
||||
become: true
|
||||
package:
|
||||
name: smartmontools
|
||||
|
||||
- name: Find path of smartctl
|
||||
shell: which smartctl
|
||||
register: which_smartctl
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
become: true
|
||||
|
||||
- name: Ensure telegraf user can execute smartctl
|
||||
blockinfile:
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK (Ensure telegraf user can execute smartctl)"
|
||||
dest: "/etc/sudoers.d/telegraf"
|
||||
block: "telegraf ALL=(root) NOPASSWD: {{ which_smartctl.stdout }}"
|
||||
create: true
|
||||
become: true
|
||||
notify:
|
||||
- Restart Telegraf
|
||||
|
||||
when: "'smart' in telegraf_plugins_extra and not telegraf_agent_docker"
|
||||
|
||||
- name: Configure system for for sensors plugin
|
||||
block:
|
||||
- name: Debian | Install lm-sensors
|
||||
package:
|
||||
name: lm-sensors
|
||||
become: true
|
||||
notify:
|
||||
- Restart Telegraf
|
||||
when: ansible_os_family == "Debian"
|
||||
- name: RedHat | Install lm-sensors
|
||||
package:
|
||||
name: lm_sensors
|
||||
become: true
|
||||
notify:
|
||||
- Restart Telegraf
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
when: "'sensors' in telegraf_plugins_extra and not telegraf_agent_docker"
|
||||
|
128
tasks/configure_macos.yml
Normal file
128
tasks/configure_macos.yml
Normal file
@ -0,0 +1,128 @@
|
||||
---
|
||||
# description: Configure telegraf and get all relevent ec2 information
|
||||
|
||||
- name: Retrieve ec2 facts
|
||||
ec2_metadata_facts:
|
||||
when:
|
||||
- telegraf_agent_aws_tags
|
||||
|
||||
- name: "Add prefix path"
|
||||
set_fact:
|
||||
telegraf_agent_config_path: /usr/local/etc
|
||||
when:
|
||||
- ansible_os_family in ["FreeBSD", "Darwin"]
|
||||
|
||||
- name: Retrieve all ec2 tags on the instance
|
||||
ec2_tag:
|
||||
region: '{{ ansible_ec2_placement_region }}'
|
||||
resource: '{{ ansible_ec2_instance_id }}'
|
||||
state: list
|
||||
when:
|
||||
- telegraf_agent_aws_tags
|
||||
register: ec2_tags
|
||||
|
||||
- name: "Copy the template for versions < 0.10.0"
|
||||
template:
|
||||
src: etc-opt-telegraf-telegraf.conf.j2
|
||||
dest: /etc/opt/telegraf/telegraf.conf
|
||||
owner: "{{ telegraf_mac_user }}"
|
||||
group: "{{ telegraf_mac_group }}"
|
||||
mode: 0640
|
||||
become: yes
|
||||
when:
|
||||
- telegraf_agent_version is version_compare('0.10.0', '<')
|
||||
notify:
|
||||
- Restart Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Copy the template for versions >= 0.10.0"
|
||||
template:
|
||||
src: telegraf.conf.j2
|
||||
dest: "{{ telegraf_agent_config_path }}/telegraf.conf"
|
||||
owner: "{{ telegraf_mac_user }}"
|
||||
group: "{{ telegraf_mac_group }}"
|
||||
mode: 0640
|
||||
become: yes
|
||||
when:
|
||||
- telegraf_agent_version is version_compare('0.10.0', '>=')
|
||||
notify:
|
||||
- Restart MacOS Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Check if extra plugins directory exists in case of exclusive"
|
||||
stat:
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d"
|
||||
register: telegraf_directory
|
||||
when:
|
||||
- telegraf_plugins_extra_exclusive
|
||||
|
||||
- name: "Delete telegraf extra plugin path"
|
||||
file:
|
||||
state: absent
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||
when:
|
||||
- telegraf_plugins_extra_exclusive
|
||||
- telegraf_directory.stat.exists
|
||||
become: yes
|
||||
notify:
|
||||
- Restart MacOS Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Create telegraf extra plugin path"
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||
owner: "{{ telegraf_mac_user }}"
|
||||
group: "{{ telegraf_mac_group }}"
|
||||
mode: 0755
|
||||
when:
|
||||
- telegraf_plugins_extra_exclusive
|
||||
- telegraf_directory.stat.exists
|
||||
become: yes
|
||||
notify:
|
||||
- Restart MacOS Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Copy telegraf extra plugins"
|
||||
template:
|
||||
src: "telegraf-extra-plugin.conf.j2"
|
||||
dest: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
|
||||
owner: "{{ telegraf_mac_user }}"
|
||||
group: "{{ telegraf_mac_group }}"
|
||||
mode: 0640
|
||||
with_dict: "{{ telegraf_plugins_extra }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
when:
|
||||
- telegraf_plugins_extra is defined
|
||||
- telegraf_plugins_extra is iterable
|
||||
- item.value.state|default('present') != 'absent'
|
||||
become: yes
|
||||
notify:
|
||||
- Restart MacOS Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Remove telegraf extra plugins"
|
||||
file:
|
||||
path: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
|
||||
state: absent
|
||||
with_dict: "{{ telegraf_plugins_extra }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
when:
|
||||
- telegraf_plugins_extra is defined
|
||||
- telegraf_plugins_extra is iterable
|
||||
- item.value.state|default('present') == 'absent'
|
||||
become: yes
|
||||
notify:
|
||||
- Restart MacOS Telegraf
|
||||
- Restart Telegraf container
|
||||
|
||||
- name: "Force restart service after reread config"
|
||||
meta: flush_handlers
|
||||
|
||||
- name: "Start Telegraf (If it wasn't running)"
|
||||
shell: brew services start telegraf
|
||||
register: brew_services_start_telegraf
|
||||
changed_when: '"Successfully started `telegraf`" in brew_services_start_telegraf.stdout'
|
||||
when: not telegraf_agent_docker
|
@ -18,15 +18,30 @@
|
||||
include_tasks: "Suse.yml"
|
||||
when: ansible_os_family == "Suse" and not telegraf_agent_docker
|
||||
|
||||
- name: "Install on FreeBSD"
|
||||
include_tasks: "FreeBSD.yml"
|
||||
when:
|
||||
- ansible_os_family == "FreeBSD" and not telegraf_agent_docker
|
||||
|
||||
- name: "Install on MacOS"
|
||||
include_tasks: "MacOS.yml"
|
||||
when:
|
||||
- ansible_os_family == "Darwin" and not telegraf_agent_docker
|
||||
|
||||
- include_tasks: "docker.yml"
|
||||
when: telegraf_agent_docker
|
||||
|
||||
- name: "Configure Telegraf"
|
||||
include_tasks: "configure_linux.yml"
|
||||
when:
|
||||
- ansible_os_family != "Windows"
|
||||
- ansible_os_family not in ['Windows', 'Darwin']
|
||||
|
||||
- name: "Install / Configure telegraf on Windows"
|
||||
include_tasks: "configure_windows.yml"
|
||||
when:
|
||||
- ansible_os_family == "Windows" and not telegraf_agent_docker
|
||||
|
||||
- name: "Install / Configure telegraf on MacOS"
|
||||
include_tasks: "configure_macos.yml"
|
||||
when:
|
||||
- ansible_os_family == "Darwin" and not telegraf_agent_docker
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
{% if telegraf_agent_aws_tags == true and ec2_tags is defined and ec2_tags != None %}
|
||||
{% for key, value in ec2_tags.tags.iteritems()%}
|
||||
{{telegraf_agent_aws_tags_prefix}}{{ key }} = "{{ value }}"
|
||||
"{{telegraf_agent_aws_tags_prefix}}{{ key }}" = "{{ value }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
@ -27,6 +27,16 @@
|
||||
{{ items }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if item.value.filter is defined %}
|
||||
{% if item.value.filter.name is defined %}
|
||||
[inputs.{{ item.value.plugin | default(item.key) }}.{{ item.value.filter.name | default("grok") }}]
|
||||
{% if item.value.filter.config is defined and item.value.filter.config is iterable %}
|
||||
{% for items in item.value.filter.config %}
|
||||
{{ items }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if item.value.objects is defined and item.value.objects is iterable %}
|
||||
{% for object in item.value.objects %}
|
||||
[[inputs.{{ item.value.plugin | default(item.key) }}.object]]
|
||||
@ -37,3 +47,11 @@
|
||||
IncludeTotal = {{ object.total | default(false) | string | lower }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if item.value.queries is defined and item.value.queries is iterable %}
|
||||
{% for query in item.value.queries %}
|
||||
[[inputs.{{ item.value.plugin | default(item.key) }}.query]]
|
||||
{% for item in item.value.queries[query] %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
@ -8,8 +8,8 @@
|
||||
{% endif %}
|
||||
|
||||
{% if telegraf_agent_aws_tags == true and ec2_tags is defined and ec2_tags != None %}
|
||||
{% for key, value in ec2_tags.tags.iteritems()%}
|
||||
{{telegraf_agent_aws_tags_prefix}}{{ key }} = "{{ value }}"
|
||||
{% for key, value in ec2_tags.tags.items()%}
|
||||
"{{telegraf_agent_aws_tags_prefix}}{{ key }}" = "{{ value }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
Reference in New Issue
Block a user