diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..0e5316a --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,42 @@ +--- +name: Test deployment +'on': + pull_request: + push: + schedule: + # Run every Wednesday at 01:42 + - cron: "42 1 * * 3" + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out codebase + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: pip3 install yamllint + - name: Lint repository + run: yamllint . + + molecule: + name: Molecule + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: pip3 install ansible molecule[docker] docker pytest testinfra + - name: Run Molecule + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' diff --git a/README.md b/README.md index e331848..9146891 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Test deployment](https://github.com/GeekOops/geekoops-collectd/actions/workflows/CI.yml/badge.svg)](https://github.com/GeekOops/geekoops-collectd/actions/workflows/CI.yml) + # geekoops-collectd Easy ansible role to setup `collectd`. Currently only `influxdb` is supported by this role. This ansible role works with diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..1327040 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include geekoops-collectd" + include_role: + name: "geekoops-collectd" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..2c75ded --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: leap15_2 + image: grisu48/leap-ansible + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + capabilities: + - SYS_ADMIN + tmpfs: + - /run + - /tmp +provisioner: + name: ansible + inventory: + host_vars: + leap15_2: + nodename: "jellyfish" +verifier: + name: testinfra + lint: + name: flake8 +lint: | + set -e + yamllint . diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100755 index 0000000..d343c75 --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +import testinfra.utils.ansible_runner +import os + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + +def test_collectd(host): + # Just ensure, the collectd config file is overwritten + cmd = host.run("cat /etc/collectd.conf | grep Hostname | grep jellyfish") + assert cmd.succeeded diff --git a/tasks/main.yml b/tasks/main.yml index 0c3d1f7..58534a1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,10 +9,24 @@ - name: Install collectd package: name: "{{ packages }}" + # Important: Leave state: present, as we will overwrite the existing config + # when this task changes! state: present register: install tags: ['collectd'] +- name: Perform collectd first config + template: + src: collectd.conf.j2 + dest: /etc/collectd.conf + owner: root + group: root + mode: 0640 + force: true + tags: ['collectd'] + when: install.changed == true + notify: restart collectd + - name: Ensure collectd is configured template: src: collectd.conf.j2 @@ -20,8 +34,9 @@ owner: root group: root mode: 0640 - force: "{{overwrite}} or install.changed" + force: "{{overwrite}}" tags: ['collectd'] + when: install.changed == false notify: restart collectd - name: Ensure collectd is enabled @@ -30,4 +45,3 @@ state: started enabled: true tags: ['collectd'] - diff --git a/vars/main.yml b/vars/main.yml index c491f20..6e6daec 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for geekoops-collectd \ No newline at end of file +# vars file for geekoops-collectd