Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add telegraf user to haproxy group #14

Merged
merged 2 commits into from
Apr 19, 2024
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
3 changes: 3 additions & 0 deletions molecule/default/files/ansible-inputs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

[[inputs.diskio]]

[[inputs.haproxy]]
servers = ["/run/haproxy/admin.sock"]

[[inputs.kernel]]

[[inputs.mem]]
Expand Down
3 changes: 3 additions & 0 deletions molecule/default/inventory/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ telegraf_group_inputs:
filestat:
files:
- "/var/log/**.log"
haproxy:
servers:
- "/run/haproxy/admin.sock"
processes:
_enabled: "{{ inventory_hostname == 'instance' }}"

Expand Down
3 changes: 2 additions & 1 deletion molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
- name: Prepare
hosts: all
tasks:
- name: Update apt cache
- name: Update apt cache and install HAProxy
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
name: haproxy
9 changes: 9 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
register: result
failed_when: result is changed

- name: Retrieve telegraf user groups
ansible.builtin.getent:
database: group
key: haproxy

- name: Check telegraf user is a member of the haproxy group
ansible.builtin.fail:
when: '"telegraf" not in ansible_facts.getent_group.haproxy'

- name: Ensure Telegraf configuration files are correct
ansible.builtin.copy:
src: "{{ item | basename }}"
Expand Down
5 changes: 4 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@
append: true
# groups may not exist yet ¯\_(ツ)_/¯
ignore_errors: true # noqa ignore-errors
when: item in _telegraf_inputs
when:
- item in _telegraf_inputs
- _telegraf_inputs[item]._enabled | d(True)
loop:
- docker
- haproxy
notify: restart telegraf
vars:
_telegraf_inputs: >-
Expand Down
2 changes: 1 addition & 1 deletion templates/telegraf-macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% macro telegraf_format_option(option, value) -%}
{% if value is string %}
{{ option }} = "{{ value }}"
{% elif value is bool %}
{% elif value is boolean %}
{{ option }} = {{ value | string | lower }}
{% elif value is list %}
{% if value %}
Expand Down
4 changes: 0 additions & 4 deletions test_plugins/type_tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
def test_bool(value):
return isinstance(value, bool)

def test_list(value):
return isinstance(value, list)

class TestModule(object):

def tests(self):
return {
'bool': test_bool,
'list': test_list
}