mirror of
https://github.com/dj-wasabi/ansible-telegraf.git
synced 2025-07-17 08:46:37 +00:00
* Moved the when statements into multiple lines;
* Updated the Molecule *.yml file to newer version; * Added a influxdb container, so telegraf will start properly on debian/ubuntu;
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
FROM {{ item.image }}
|
||||
# Molecule managed
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python python-devel python2-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && 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 update -y && 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; fi
|
||||
{% 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
|
||||
|
@ -2,14 +2,22 @@
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: False
|
||||
gather_facts: false
|
||||
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
||||
vars:
|
||||
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
|
||||
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
|
||||
molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
|
||||
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
|
||||
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"
|
||||
@ -20,6 +28,7 @@
|
||||
- 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
|
||||
|
||||
@ -27,21 +36,49 @@
|
||||
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) }}"
|
||||
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 }}"
|
||||
hostname: "{{ 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: none
|
||||
command: "{{ item.command | default('sleep infinity') }}"
|
||||
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 }}"
|
||||
|
@ -2,15 +2,31 @@
|
||||
- name: Destroy
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: False
|
||||
gather_facts: false
|
||||
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
||||
vars:
|
||||
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
|
||||
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
|
||||
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) }}"
|
||||
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 }}"
|
||||
|
@ -10,27 +10,37 @@ lint:
|
||||
|
||||
platforms:
|
||||
- name: influxdb
|
||||
image: influxdb
|
||||
privileged: True
|
||||
image: influxdb:1.7-alpine
|
||||
command: influxd
|
||||
groups:
|
||||
- influxdb
|
||||
- tsdb
|
||||
networks:
|
||||
- name: telegraf
|
||||
environment:
|
||||
INFLUXDB_DB: telegraf
|
||||
- name: telegraf-centos
|
||||
image: milcom/centos7-systemd
|
||||
privileged: True
|
||||
groups:
|
||||
- telegraf
|
||||
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
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
@ -39,6 +49,12 @@ provisioner:
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
telegraf_agent_output:
|
||||
- type: influxdb
|
||||
config:
|
||||
- urls = ["http://influxdb:8086"]
|
||||
- database = "telegraf"
|
||||
- precision = "s"
|
||||
telegraf_plugins_extra:
|
||||
percpu-usage:
|
||||
plugin: cpu
|
||||
@ -61,9 +77,6 @@ provisioner:
|
||||
- plugin: netstat
|
||||
- plugin: processes
|
||||
- plugin: kernel
|
||||
- plugin: nginx
|
||||
config:
|
||||
- urls = ["http://localhost/nginx_status"]
|
||||
|
||||
scenario:
|
||||
name: default
|
||||
|
@ -1,4 +1,4 @@
|
||||
---
|
||||
- hosts: all
|
||||
- hosts: telegraf
|
||||
roles:
|
||||
- role: ansible-telegraf
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
|
||||
- hosts: all
|
||||
- hosts: telegraf
|
||||
tasks:
|
||||
- name: "Installing which on CentOS"
|
||||
yum:
|
||||
|
@ -3,14 +3,13 @@ import os
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('telegraf')
|
||||
|
||||
|
||||
def test_telegraf_running_and_enabled(Service, SystemInfo):
|
||||
def test_telegraf_running_and_enabled(Service):
|
||||
telegraf = Service("telegraf")
|
||||
assert telegraf.is_enabled
|
||||
if SystemInfo.distribution == 'centos':
|
||||
assert telegraf.is_running
|
||||
assert telegraf.is_running
|
||||
|
||||
|
||||
def test_telegraf_dot_conf(File):
|
||||
@ -18,7 +17,20 @@ def test_telegraf_dot_conf(File):
|
||||
assert telegraf.user == "telegraf"
|
||||
assert telegraf.group == "telegraf"
|
||||
assert telegraf.mode == 0o640
|
||||
assert telegraf.contains('interval = "10s"')
|
||||
assert telegraf.contains('[[inputs.cpu]]')
|
||||
assert telegraf.contains('percpu = true')
|
||||
assert telegraf.contains('[[outputs.influxdb]]')
|
||||
assert telegraf.contains('["http://influxdb:8086"]')
|
||||
assert telegraf.contains('[[inputs.net]]')
|
||||
|
||||
|
||||
def test_telegraf_dot_d_dir(File):
|
||||
telegraf = 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):
|
||||
|
Reference in New Issue
Block a user