64 Commits

Author SHA1 Message Date
7f00767dc2 Merge pull request #131 from dj-wasabi/add-requirements-ci
Removing requirements file and use it from dj-wasabi-release repo
2020-10-16 16:05:29 +02:00
04935c3de4 Changing requirements file, removing leap 2020-10-16 15:56:44 +02:00
23f8339d99 Merge branch 'master' into add-requirements-ci 2020-10-16 15:47:41 +02:00
9b912d8f97 Added proper newline 2020-10-16 15:37:21 +02:00
07a0358410 Merge pull request #132 from NotDead/master
corrected "Example Docker configuration" to make it work by default
2020-09-07 07:49:04 +02:00
0b749fba5e corrected "Example Docker configuration" to make it work by default 2020-09-06 22:28:44 +03:00
559081b000 Removing requirements file and use it from ci-base repo 2020-09-01 16:02:05 +02:00
562a751990 Update README.md
Corrected badge
2020-08-31 18:15:59 +02:00
0ad660efb8 Merge pull request #130 from dj-wasabi/add-to-github-actions
Going to Github Actions
2020-08-01 18:50:39 +02:00
bffd2f1549 Added leap 2020-08-01 18:41:39 +02:00
998ad25059 Fixed some things to make it work: 2020-08-01 17:54:49 +02:00
a5dc1b8de5 Added leap and fixed installation of packages 2020-08-01 16:42:25 +02:00
bc3b670ca2 Corrected name and removed the scenario 2020-08-01 16:25:54 +02:00
add696bc78 Added requirements file;Removed some collection stuff 2020-08-01 16:24:03 +02:00
1112020f45 Going to Github Actions 2020-08-01 16:21:47 +02:00
6e72a8f278 Create FUNDING.yml 2020-07-31 10:08:30 +02:00
7508f3927d Merge pull request #127 from wingcon/master
made service status configurable
2020-07-10 15:32:35 +02:00
79422a70a1 Merge pull request #129 from comtravo/chore/fix-aws-tags
quote aws ec2 global tags
2020-07-10 15:32:19 +02:00
d3195b7b88 quote aws ec2 tags 2020-07-10 14:51:38 +02:00
20a7653f95 made service status configurable 2020-06-23 17:14:15 +02:00
08b1c62710 Merge pull request #126 from carlba/plugin-dependencies
Plugin dependencies are installed and configured
2020-06-14 20:57:15 +02:00
4b10834a00 Plugin dependencies are installed and configured 2020-06-13 15:50:19 +02:00
9353a544f9 Merge pull request #123 from carlba/macos-support
MacOS support
2020-06-13 11:16:07 +02:00
d750f4d259 Addressed PR Comments 2020-06-13 10:42:26 +02:00
7c32a52748 Merge pull request #124 from dwerder/fix-debian-latest-comparison
fix debian packagename on state latest
2020-06-03 09:05:25 +02:00
7a1ae28929 fix debian for package state
Closes #121
2020-06-02 15:52:07 +02:00
59b3613fe1 Deployment for MacOS 2020-05-23 19:35:20 +02:00
987aeb4406 Ensured role presented correctly on Ansible Galaxy 2020-05-23 18:32:29 +02:00
b15e674884 Merge pull request #122 from marcinwito/gpg_yum_repo_fix
gpgkey yum repo fix
2020-05-19 15:10:19 +02:00
331ffb7cb5 gpgkey yum repo fix 2020-05-19 13:40:18 +02:00
ea64e9bac4 Merge pull request #120 from rohit-gohri/patch-1
Fix RedHat task list
2020-05-08 20:48:41 +02:00
292cc2a2f4 Also add become for installation 2020-04-22 20:45:16 +05:30
685487f198 Fix omit syntax 2020-04-22 19:52:34 +05:30
7b8809c311 Add yum_repo as privileged user
For #119
2020-04-22 19:45:15 +05:30
8fdab6fdcd Merge pull request #117 from wingcon/master
added installation method manual - skip installation
2020-03-18 20:54:32 +01:00
7d5d5c1ea1 added installation method manual - skip installation 2020-03-18 17:43:33 +01:00
7d89ab270a Merge pull request #116 from rlex/pgsql_extensible_queries
Support postgresql_extensible queries
2020-03-02 07:38:00 +01:00
4956663701 add queries var to template 2020-02-27 22:09:58 +03:00
67253f5438 Merge pull request #113 from dj-wasabi/add-sub-configuration
Added extra filtering possibilities for a plugin
2020-02-04 12:54:55 +01:00
a55ef0b0c0 Added extra filtering possibilities for a plugin 2019-12-01 16:23:09 +01:00
0006d91e5e Updating documentation regarding issue 105;Added Toc;Added badges 2019-12-01 12:02:36 +01:00
10193da1cf Forgot to update changelog 2019-12-01 11:57:31 +01:00
a4c6db7be1 Merge pull request #112 from dj-wasabi/fix-travis
Minor changes to get Travis working again
2019-10-24 13:35:00 +02:00
02d6e48a39 Minor changes to get Travis working again 2019-10-24 13:11:42 +02:00
e977863e97 Merge pull request #98 from dj-wasabi/make-use-of-proxy
Added the use_proxy argument to use a proxy (or not)
2019-09-28 12:19:38 +02:00
a1505ad499 Merge pull request #109 from dj-wasabi/download-from-influxdb
Download from influxdb
2019-09-10 07:07:46 +02:00
a4cf4827cc Merge pull request #108 from matttrach/patch-1
Don't override package name unless "latest"
2019-09-10 07:06:05 +02:00
b48ff6b273 Don't override package name unless "latest" 2019-09-04 18:09:18 -05:00
2687513dc8 Merge pull request #106 from remkade/arm64_support
Adding support for arm64 systems
2019-08-23 07:04:38 +02:00
341a00f16d Adding support for arm64 systems
Adds support for `arm64` based systems (AWS `a1.*` instances).
2019-08-22 15:44:57 -07:00
4b6f773bba Merge pull request #104 from diego1q2w/patch-1
Use items() instead of iteritems()
2019-06-22 10:39:31 +02:00
ff9a820b01 Use items() instead of iteritems()
Python3 doesn't support iteritems()
2019-06-21 13:28:18 +02:00
dec1cab940 Merge pull request #103 from asfaltboy/fix/update-apt-cache
Fix: ensure apt-cache is updated before install
2019-05-28 20:40:56 +02:00
4fdafac2d0 fix: ensure apt-cache is updated before install 2019-05-28 19:54:13 +02:00
0c500cf06d Merge pull request #102 from langerma/FreeBSD
on FreeBSD the telegeraf.conf is in root of /usr/local/etc.
2019-05-01 10:22:24 +02:00
ab68b6813b on FreeBSD the telegeraf.conf is in root of /usr/local/etc. so i changed the telegraf_agent_config_path. now the telegraf rc scripts finds the right config and now error about missing directories is thrown. 2019-05-01 10:03:08 +02:00
852cfaa55e Merge pull request #101 from dj-wasabi/minor-changes-for-freebsd
Some changes for fixing FreeBSD
2019-04-27 16:22:01 +02:00
3fdba74518 Some changes for fixing FreeBSD 2019-04-27 16:09:29 +02:00
f843a3f51a Merge pull request #100 from langerma/FreeBSD
basic FreeBSD support
2019-04-27 15:41:04 +02:00
4ab32df6df basic FreeBSD support 2019-04-25 23:52:06 +02:00
ca4a07f87d As per comment in issue the environment argument should be provided 2019-04-21 19:50:14 +02:00
3cd91d0316 Added the use_proxy argument to use a proxy (or not) 2019-04-21 18:51:26 +02:00
27f2665772 Merge pull request #97 from dj-wasabi/minor-changes-for-molecule
Various small changes for molecule
2019-04-21 18:29:24 +02:00
a11694ff86 Various small changes for molecule 2019-04-21 18:17:54 +02:00
32 changed files with 545 additions and 294 deletions

4
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: dj-wasabi
patreon: wernerdijkerman

65
.github/workflows/telegraf.yml vendored Normal file
View 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
View File

@ -5,3 +5,5 @@ tests/.cache
__pycache__
*.retry
pmip
# IDE:s
.idea

11
.pre-commit-config.yaml Normal file
View 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

View File

@ -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/

View File

@ -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!))

View File

@ -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:
[![Build Status](https://travis-ci.org/dj-wasabi/ansible-telegraf.svg?branch=master)](https://travis-ci.org/dj-wasabi/ansible-telegraf)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fdj-wasabi%2Fansible-telegraf%2Fbadge%3Fref%3Dmaster&style=flat)](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

View File

@ -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

View File

@ -20,3 +20,6 @@
name: Telegraf
start_mode: auto
state: restarted
- name: "Restart MacOS Telegraf"
shell: brew services restart telegraf

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 }}"

View File

@ -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 }}"

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -1,9 +0,0 @@
---
extends: default
rules:
line-length:
max: 180
level: warning
truthy: disable

View File

@ -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
View 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
View 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"

View File

@ -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"

View File

@ -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
View 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

View File

@ -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

View File

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

View File

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

View File

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