Skip to content

Commit

Permalink
implement opn_check_mk_local_checks var as dict of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Oct 17, 2024
1 parent 3adb7f5 commit 5f0613e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
20 changes: 12 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ opn_check_mk_port: 6556
opn_check_mk_patches:
- check_mk_agent-freeipmi.p0 # https://github.com/Rosa-Luxemburgstiftung-Berlin/ansible-opnsense-checkmk/issues/24

# list of plugins and local checks to install
# dict of plugins and local checks to install
# new ! - we use a dict of lists in order to allow
# adding additional checks per hosts / groups etc.
# the old list syntax opn_check_mk_local_checks: [] is still supported
opn_check_mk_local_checks:
- gateways_status.py
- crash_status.py
- firmware_status.py
- pkg_audit.py
- pkg_check.sh
- pfctl_status.sh
- check_powerunit.sh
all:
- gateways_status.py
- crash_status.py
- firmware_status.py
- pkg_audit.py
- pkg_check.sh
- pfctl_status.sh
- check_powerunit.sh

# dict of additional files: file name => dest
# example:
Expand Down
18 changes: 16 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,26 @@
- "{{ item | basename }}"
when: opn_install_check_mk

- name: convert deprecated format from list to dict for opn_check_mk_local_checks
ansible.builtin.set_fact:
opn_check_mk_local_checks: "{ 'deprecated' : {{ opn_check_mk_local_checks }} }"
when: opn_check_mk_local_checks | type_debug == "list"

- name: create a uniq list of opn_check_mk_local_checks for internal use
ansible.builtin.set_fact:
_opn_check_mk_local_checks: "{{ opn_check_mk_local_checks.values() | list | flatten | unique | list }}"

- name: debug _opn_check_mk_local_checks
ansible.builtin.debug:
var: _opn_check_mk_local_checks
verbosity: 1

- name: create check_mk local checks cache dirs
ansible.builtin.file:
path: "{{ opn_check_mk_lib_dir }}/local/{{ item }}"
state: directory
mode: 0755
with_items: "{{ opn_check_mk_local_checks | map('dirname') | unique | list }}"
with_items: "{{ _opn_check_mk_local_checks | map('dirname') | unique | list }}"
when:
- opn_install_check_mk
- item | length > 0
Expand All @@ -95,7 +109,7 @@
src: "{{ lookup('ansible.builtin.first_found', _firstfound) }}"
dest: "{{ opn_check_mk_lib_dir }}/local/{{ item }}"
mode: 0700
with_items: "{{ opn_check_mk_local_checks }}"
with_items: "{{ _opn_check_mk_local_checks }}"
vars:
_firstfound:
paths:
Expand Down

0 comments on commit 5f0613e

Please sign in to comment.