Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Test install, config and configs tasks #2

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/*.retry
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: generic

sudo: required

services:
- docker

before_install:
- docker pull manala/ansible-debian:wheezy
- docker pull manala/ansible-debian:jessie

script:
- make lint@wheezy
- make test@wheezy
- make lint@jessie
- make test@jessie

notifications:
webhooks:
urls:
- https://galaxy.ansible.com/api/v1/notifications/
- https://webhooks.gitter.im/e/430e0a92ad6370b7b805
on_success: change
on_failure: always
on_start: never
104 changes: 104 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.SILENT:
.PHONY: help

## Colors
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m

## Role
ROLE_NAME = manala.telegraf

## Macros
DOCKER = docker run \
--rm \
--volume `pwd`:/etc/ansible/roles/${ROLE_NAME} \
--volume `pwd`:/srv \
--cap-add SYS_PTRACE \
--workdir /srv \
--tty \
${DOCKER_OPTIONS} \
manala/ansible-debian:${DEBIAN_DISTRIBUTION} \
${DOCKER_COMMAND}

## Help
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
printf " make [target]\n\n"
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n"
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

#######
# Dev #
#######

dev@wheezy: DEBIAN_DISTRIBUTION = wheezy
dev@wheezy: DOCKER_OPTIONS = --interactive
dev@wheezy: DOCKER_COMMAND = /bin/bash
dev@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

dev@jessie: DEBIAN_DISTRIBUTION = jessie
dev@jessie: DOCKER_OPTIONS = --interactive
dev@jessie: DOCKER_COMMAND = /bin/bash
dev@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

########
# Lint #
########

lint@wheezy: DEBIAN_DISTRIBUTION = wheezy
lint@wheezy: DOCKER_COMMAND = make lint
lint@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

lint@jessie: DEBIAN_DISTRIBUTION = jessie
lint@jessie: DOCKER_COMMAND = make lint
lint@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

lint:
ansible-lint -v .

########
# Test #
########

test@wheezy: DEBIAN_DISTRIBUTION = wheezy
test@wheezy: DOCKER_COMMAND = sh -c 'make test'
test@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

test@jessie: DEBIAN_DISTRIBUTION = jessie
test@jessie: DOCKER_COMMAND = sh -c 'make test'
test@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

test: test-install test-config test-configs

test-install:
ansible-playbook tests/install.yml --syntax-check
ansible-playbook tests/install.yml

test-config:
ansible-playbook tests/config.yml --syntax-check
ansible-playbook tests/config.yml

test-configs:
ansible-playbook tests/configs.yml --syntax-check
ansible-playbook tests/configs.yml
72 changes: 40 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Ansible Role: Telegraf
# Ansible Role: Telegraf [![Build Status](https://travis-ci.org/manala/ansible-role-telegraf.svg?branch=master)](https://travis-ci.org/manala/ansible-role-telegraf)

This role will deal with the setup and the config of influxdata Telegraf.
This role will deal with the setup and the config of [influxdata Telegraf](https://github.com/influxdata/telegraf).

It's part of the Manala <a href="http://www.manala.io" target="_blank">Ansible stack</a> but can be used as a stand alone component.

## Requirements

None
This role is made to work with the __telegraf__ official debian packages, available on the [__influxdata__ debian repository](https://www.influxdata.com/package-repository-for-linux/). Please use the [**manala.apt**](https://galaxy.ansible.com/manala/apt/) role to handle it properly.

## Installation

Expand All @@ -32,42 +32,50 @@ Using ansible galaxy requirements file:

## Role Variables

### Example
| Name | Default | Type | Description |
| ---------------------------------- | ---------------------- | ------ | -------------------------------------------------------------------------- |
| `manala_telegraf_config_template` | config/empty.j2 | String | Telegraf config base template |
| `manala_telegraf_config` | [] | Array | Telegraf config directives |
| `manala_telegraf_configs_template` | configs/default.j2 | String | Telegraf configs base template |
| `manala_telegraf_configs` | [] | Array | Telegraf additional configs |
| `manala_telegraf_configs_exclusive`| false | Array | If true, will remove extra files in /etc/telegraf/telegraf.d |

## Playbook
### Configuration example

See https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md

```yaml
- hosts: all
roles:
- role: manala.telegraf
manala_telegraf_config:
- agent:
- hostname: "{{ ansible_fqdn }}"
- quiet: true

manala_telegraf_configs_exclusive: true
manala_telegraf_configs:
- file: output_influxdb.conf
template: configs/output_influxdb.conf.j2
config:
- urls: ["udp://127.0.0.1:8090"]
- database: telegraf
- username: telegraf
- password: password

- file: input_system.conf
template: configs/input_system.conf.j2

- file: input_cpu.conf
template: configs/input_cpu.conf.j2

- file: input_custom.conf
template: "{{ playbook_dir }}/templates/telegraf/input_custom.conf.j2"
```

## Group/host vars
## Example playbook

```yaml
manala_telegraf_config:
- agent:
- hostname: "{{ ansible_fqdn }}"
- quiet: true

manala_telegraf_configs_exclusive: true
manala_telegraf_configs:
- file: output_influxdb.conf
template: configs/output_influxdb.conf.j2
config:
- urls: ["udp://127.0.0.1:8090"]
- database: telegraf
- username: telegraf
- password: password

- file: input_system.conf
template: configs/input_system.conf.j2

- file: input_cpu.conf
template: configs/input_cpu.conf.j2

- file: input_custom.conf
template: "{{ playbook_dir }}/templates/telegraf/input_custom.conf.j2"
- hosts: all
roles:
- { role: manala.telegraf }
```

# Licence
Expand Down
30 changes: 30 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

- hosts: all

vars:
manala_telegraf_config:
- agent:
- hostname: test.manala.dev
- quiet: true

pre_tasks:
- include: pre_tasks/disable_systemd.yml
- include: pre_tasks/apt.yml

roles:
- manala.telegraf

post_tasks:
- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- process:
telegraf:
running: true
- file:
/etc/telegraf/telegraf.conf:
exists: true
contains:
- hostname = \"test.manala.dev\"
- quiet = true
51 changes: 51 additions & 0 deletions tests/configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---

- hosts: all

vars:
manala_telegraf_configs:
- file: input_cpu.conf
template: configs/input_cpu.conf.j2
config:
- percpu: true
- totalcpu: false
- fielddrop: [cpu_time]
- tags:
- tag-1: foo
- tag-2: bar
- tagdrop:
- cpu: [cpu6, cpu7]
- file: custom.conf
template: "{{ playbook_dir }}/templates/custom.j2"

pre_tasks:
- include: pre_tasks/disable_systemd.yml
- include: pre_tasks/apt.yml

roles:
- manala.telegraf

post_tasks:
- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- process:
telegraf:
running: true
- file:
/etc/telegraf/telegraf.d/input_cpu.conf:
exists: true
contains:
- percpu = true
- totalcpu = false
- fielddrop = [\"cpu_time\"]
- '[inputs.cpu.tags]'
- tag-1 = \"foo\"
- tag-2 = \"bar\"
- '[inputs.cpu.tagdrop]'
- cpu = [\"cpu6\", \"cpu7\"]
/etc/telegraf/telegraf.d/custom.conf:
exists: true
contains:
- '[[inputs.cpu]]'
- percpu = false
21 changes: 21 additions & 0 deletions tests/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

- hosts: all

pre_tasks:
- include: pre_tasks/disable_systemd.yml
- include: pre_tasks/apt.yml

roles:
- manala.telegraf

post_tasks:
- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- package:
telegraf:
installed: true
- process:
telegraf:
running: true
26 changes: 26 additions & 0 deletions tests/pre_tasks/apt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

- name: Pre tasks > Clean telegraf packages
apt:
package: telegraf*
state: absent
purge: true
ignore_errors: true

- name: Pre tasks > Clean telegraf config
file:
path: "{{ item }}"
state: absent
with_items:
- /etc/telegraf
- /etc/default/telegraf
- /var/log/telegraf

- name: Pre tasks > Influxdata apt key
apt_key:
url: https://repos.influxdata.com/influxdb.key
id: 2582E0C5

- name: Pre tasks > Influxdata apt repository
apt_repository:
repo: deb https://repos.influxdata.com/debian {{ ansible_distribution_release }} stable
6 changes: 6 additions & 0 deletions tests/pre_tasks/disable_systemd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- name: Pre tasks > Disable systemctl to force sysv init script
command: mv /bin/systemctl /bin/systemctl.disabled
ignore_errors: true
changed_when: false
2 changes: 2 additions & 0 deletions tests/templates/custom.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[inputs.cpu]]
percpu = false