Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dj-wasabi/ansible-telegraf
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-wasabi committed Oct 20, 2023
2 parents b8e8710 + 6b6aa75 commit fdcff0b
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 40 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/telegraf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ jobs:
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 on empty systems in check-mode
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 -s empty-checkmode
- name: Run role tests
run: >-
MY_MOLECULE_CONTAINER=${{ matrix.molecule_distro.container }}
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

## [Unreleased](https://github.com/dj-wasabi/ansible-telegraf/tree/HEAD)

[Full Changelog](https://github.com/dj-wasabi/ansible-telegraf/compare/0.13.3...HEAD)
[Full Changelog](https://github.com/dj-wasabi/ansible-telegraf/compare/0.14.0...HEAD)

**Implemented enhancements:**

- Fix check-mode failures [\#168](https://github.com/dj-wasabi/ansible-telegraf/pull/168) ([pieterlexis-tomtom](https://github.com/pieterlexis-tomtom))

**Fixed bugs:**

- Replace apt\_key with get\_url [\#170](https://github.com/dj-wasabi/ansible-telegraf/pull/170) ([danclough](https://github.com/danclough))

## [0.14.0](https://github.com/dj-wasabi/ansible-telegraf/tree/0.14.0) (2023-01-30)

[Full Changelog](https://github.com/dj-wasabi/ansible-telegraf/compare/0.13.3...0.14.0)

**Implemented enhancements:**

Expand Down
4 changes: 4 additions & 0 deletions molecule/empty-checkmode/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: telegraf
roles:
- role: ansible-telegraf
70 changes: 70 additions & 0 deletions molecule/empty-checkmode/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
dependency:
name: galaxy
driver:
name: docker

platforms:
- name: telegraf-${MY_MOLECULE_CONTAINER:-centos8}
image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"}
command: ${MY_MOLECULE_DOCKER_COMMAND:-""}
privileged: True
pre_build_image: True
networks:
- name: telegraf
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
groups:
- telegraf

provisioner:
name: ansible
lint:
name: ansible-lint
inventory:
group_vars:
debian:
telegraf_agent_package_method: online
all:
telegraf_agent_package_state: latest
telegraf_agent_output:
- type: influxdb
config:
- urls = ["http://influxdb:8086"]
- database = "telegraf"
- precision = "s"
telegraf_plugins_extra:
logparser:
plugin: logparser
config:
- files = ["/var/log/messages"]
- from_beginning = false
filter:
name: grok
config:
- patterns = ["invoked oom-killer"]
telegraf_aggregators:
- aggregator: basicstats
config:
- drop_original = false
- stats = ['mean']
tagpass:
- cpu = ["cpu-total"]

scenario:
name: empty-checkmode
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- check
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8
46 changes: 46 additions & 0 deletions molecule/empty-checkmode/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

- hosts: telegraf
tasks:
- name: "Installing packages on CentOS"
yum:
name: which
state: present
when:
- ansible_os_family == 'RedHat'

- name: "Apt get update"
shell: apt-get update
when:
- ansible_os_family == 'Debian'

- name: "Installing packages on Debian"
apt:
name:
- wget
- "{{ 'gnupg-agent' if ansible_distribution_major_version in ['8', '18', '16'] else 'gpg-agent' }}"
update_cache: True
state: present
when:
- ansible_os_family == 'Debian'
- ansible_distribution_major_version not in [9, 10]

- name: "Installing packages on Debian"
apt:
name:
- wget
- 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'
- ansible_distribution_major_version in [9, 10]

- name: "Installing packages on Suse"
zypper:
name:
- aaa_base
state: present
when:
- ansible_os_family == 'Suse'
32 changes: 32 additions & 0 deletions molecule/empty-checkmode/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('telegraf')


def test_telegraf_running_and_enabled(host):
telegraf = host.service("telegraf")
if host.system_info.distribution not in ['opensuse-leap']:
assert not telegraf.is_enabled
assert not telegraf.is_running


def test_telegraf_dot_conf(host):
telegraf = host.file("/etc/telegraf/telegraf.conf")
assert not telegraf.exists

def test_telegraf_dot_d_dir(host):
telegraf = host.file("/etc/telegraf/telegraf.d")
assert not telegraf.exists


def test_telegraf_dot_d(host):
telegraf = host.file("/etc/telegraf/telegraf.d/logparser.conf")
assert not telegraf.exists


def test_telegraf_package(host):
telegraf = host.package('telegraf')
assert not telegraf.is_installed
118 changes: 79 additions & 39 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,88 @@
- not apt_https_transport.stat.exists
become: yes

- name: "Debian | Download Telegraf apt key"
apt_key:
url: "https://repos.influxdata.com/influxdata-archive.key"
id: 7df8b07e
state: present
register: are_telegraf_dependencies_keys_installed
until: are_telegraf_dependencies_keys_installed is succeeded
become: yes
- name: "Debian | Configure Telegraf apt repository"
when:
- telegraf_agent_package_method == "repo"
block:
- when: (ansible_distribution == "Debian" and ansible_distribution_major_version|int < 9) or (ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int < 18)
name: "Debian | Download Telegraf apt key"
apt_key:
url: "https://repos.influxdata.com/influxdata-archive.key"
id: 7df8b07e
state: present
register: are_telegraf_dependencies_keys_installed
until: are_telegraf_dependencies_keys_installed is succeeded
become: yes
- when: (ansible_distribution == "Debian" and ansible_distribution_major_version|int >= 9) or (ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 18)
block:
- name: "Debian | Ensure the shared keyrings directory exists"
stat:
path: /usr/share/keyrings
register: usr_share_keyrings

- name: "Debian | Add Telegraf repository (using LSB)"
apt_repository:
repo: "deb https://repos.influxdata.com/{{ ansible_distribution|lower }} {{ ansible_lsb.codename }} stable"
filename: "telegraf"
state: present
become: yes
when:
- telegraf_agent_package_method == "repo"
- ansible_lsb is defined
- ansible_lsb.codename is defined
- name: "Debian | Create shared keyrings directory"
file:
state: directory
path: /usr/share/keyrings
owner: root
group: root
mode: 0755
when:
- not usr_share_keyrings.stat.exists
become: yes

- name: "Debian | Install Telegraf apt key"
get_url:
url: https://repos.influxdata.com/influxdata-archive.key
dest: /usr/share/keyrings/influxdata-archive.asc
register: are_telegraf_dependencies_keys_installed
until: are_telegraf_dependencies_keys_installed is succeeded
become: yes

- name: "Debian | Add Telegraf repository"
apt_repository:
repo: "deb https://repos.influxdata.com/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable"
filename: "telegraf"
state: present
become: yes
when:
- telegraf_agent_package_method == "repo"
- ansible_lsb is not defined or ansible_lsb.codename is not defined
- name: "Debian | Set Telegraf apt repository parameters"
set_fact:
telegraf_repository_params: "[signed-by=/usr/share/keyrings/influxdata-archive.asc]"

- name: "Debian | Add Telegraf repository (using LSB)"
copy:
content: "deb {{ telegraf_repository_params | default('') }} https://repos.influxdata.com/{{ ansible_distribution|lower }} {{ ansible_lsb.codename }} stable"
dest: /etc/apt/sources.list.d/telegraf.list
when:
- ansible_lsb is defined
- ansible_lsb.codename is defined

- name: "Debian | Add Telegraf repository"
copy:
content: "deb {{ telegraf_repository_params | default('') }} https://repos.influxdata.com/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable"
dest: /etc/apt/sources.list.d/telegraf.list
become: yes
when:
- ansible_lsb is not defined or ansible_lsb.codename is not defined

- name: "Debian | Install Telegraf package (repo)"
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"
become: yes
when:
- telegraf_agent_package_method == "repo"
ignore_errors: "{{ ansible_check_mode }}"

- name: "Debian | Install Telegraf package (repo)"
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"
become: yes
ignore_errors: "{{ ansible_check_mode }}"

- name: "Debian | Download Telegraf package (online)"
get_url:
Expand All @@ -80,18 +131,6 @@
when:
- telegraf_agent_package_method == "online"

- name: "Debian | Install Telegraf package (repo)"
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"
become: yes
when:
- telegraf_agent_package_method == "repo"

- name: "Debian | Install Telegraf package (online)"
apt:
deb: "{{ telegraf_agent_package_path }}/{{ telegraf_agent_package }}"
Expand All @@ -103,6 +142,7 @@
become: yes
when:
- telegraf_agent_package_method == "online" or telegraf_agent_package_method == "offline"
ignore_errors: "{{ ansible_check_mode }}"

- name: "Debian | Remove repository (online/offline install)"
file:
Expand Down
1 change: 1 addition & 0 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
until: is_telegraf_package_installed is succeeded
become: yes
notify: "Restart Telegraf"
ignore_errors: "{{ ansible_check_mode }}"
1 change: 1 addition & 0 deletions tasks/Suse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
register: is_telegraf_package_installed
until: is_telegraf_package_installed is succeeded
become: yes
ignore_errors: "{{ ansible_check_mode }}"

- name: "Suse | Create directories for telegraf"
file:
Expand Down
1 change: 1 addition & 0 deletions tasks/configure_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
enabled: "{{ telegraf_enabled }}"
become: yes
when: not telegraf_agent_docker
ignore_errors: "{{ ansible_check_mode }}"

- name: Configure system for for docker plugin
block:
Expand Down
1 change: 1 addition & 0 deletions tasks/configure_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@
register: brew_services_start_telegraf
changed_when: '"Successfully started `telegraf`" in brew_services_start_telegraf.stdout'
when: not telegraf_agent_docker
ignore_errors: "{{ ansible_check_mode }}"

0 comments on commit fdcff0b

Please sign in to comment.