From 1e3936767733b60888a8af7e456b573acdb8da74 Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Thu, 25 Apr 2024 14:36:32 +0100 Subject: [PATCH] updates --- .pre-commit-config.yaml | 6 +++--- tasks/check.yml | 6 +++--- templates/host.conf.j2 | 32 ++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb5fd34..a5208e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - templates # https://github.com/jackdewinter/pymarkdown/releases - repo: https://github.com/jackdewinter/pymarkdown.git - rev: 0.9.16 + rev: v0.9.18 hooks: - id: pymarkdown name: Markdown Lint @@ -34,14 +34,14 @@ repos: - README.md # https://github.com/ansible/ansible-lint/releases - repo: https://github.com/ansible/ansible-lint.git - rev: v24.2.0 + rev: v24.2.2 hooks: - id: ansible-lint name: Ansible Lint language: python additional_dependencies: # https://github.com/kellyjonbrazil/jc/releases - - jc==1.25.0 + - jc==1.25.2 # https://github.com/jmespath/jmespath.py/tags - jmespath==1.0.1 ... diff --git a/tasks/check.yml b/tasks/check.yml index bdb5fb3..c49d5f8 100644 --- a/tasks/check.yml +++ b/tasks/check.yml @@ -20,12 +20,12 @@ - name: "Ensure that ansible_host is defined for the icinga_master_nodes" ansible.builtin.assert: that: - - hostvars[icinga_master_node].ansible_host is defined - - hostvars[icinga_master_node].ansible_host is ansible.utils.ip + - hostvars[icinga_master_node_item].ansible_host is defined + - hostvars[icinga_master_node_item].ansible_host is ansible.utils.ip quiet: "{% if ansible_verbosity == 0 %}true{% else %}false{% endif %}" loop: "{{ groups['icinga_master_nodes'] }}" loop_control: - loop_var: icinga_master_node + loop_var: icinga_master_node_item when: - groups['icinga_master_nodes'] is defined - groups['icinga_master_nodes'] | length > 0 diff --git a/templates/host.conf.j2 b/templates/host.conf.j2 index 059bb0f..eeb4579 100644 --- a/templates/host.conf.j2 +++ b/templates/host.conf.j2 @@ -8,7 +8,7 @@ object Host "{{ icinga_host }}" { vars.agent_endpoint = name {% endif %} -{% if icinga_remote_node is defined and not icinga_remote_node %} +{% if icinga_remote_node is defined and not icinga_remote_node | bool %} {% if hostvars[icinga_host]['ansible_system'] is defined %} vars.os = "{{ hostvars[icinga_host]['ansible_system'] }}" {% endif %} @@ -17,28 +17,32 @@ object Host "{{ icinga_host }}" { {% endif %} {% endif %} -{% for check, config in icinga_host_checks.items() %} - vars.checks["{{ check }}"] = { -{% if config.command is defined %} - "command" = "{{ config.command }}", +{% for icinga_check, icinga_config in icinga_host_checks.items() %} + vars.checks["{{ icinga_check }}"] = { +{% if icinga_config.command is defined %} + "command" = "{{ icinga_config.command }}", {% else %} - "command" = "{{ check }}", + "command" = "{{ icinga_check }}", {% endif %} -{% if config.remote is defined %} - "remote" = {% if config.remote | bool %}true{% else %}false{% endif %}, -{% elif check is regex('^dns|http|ping|ssh$') %} +{% if icinga_config.remote is defined and icinga_config.remote | ansible.builtin.type_debug == "bool" %} + "remote" = {{ icinga_config.remote | lower }}, +{% elif icinga_check is regex('^dns|http|ping|ssh$') %} {# run dns, http, ping and ssh checks from the master #} "remote" = false, -{% elif config.command is defined and config.command is regex('^dns|http|ping|ssh$') %} +{% elif icinga_config.command is defined and icinga_config.command is regex('^dns|http|ping|ssh$') %} {# run dns, http, ping and ssh checks from the master #} "remote" = false, {% else %} {# default to running checks on the agent #} "remote" = true, {% endif %} -{% if config.args is defined %} -{% for key, value in config.args.items() %} - args["{{ key }}"] = "{{ value }}", +{% if icinga_config.args is defined %} +{% for icinga_config_key, icinga_config_value in icinga_config.args.items() %} +{% if icinga_config_value | ansible.builtin.type_debug == "bool" %} + args["{{ icinga_config_key }}"] = "{{ icinga_config_value | lower }}", +{% else %} + args["{{ icinga_config_key }}"] = "{{ icinga_config_value }}", +{% endif %} {% endfor %} {% endif %} } @@ -50,4 +54,4 @@ object Host "{{ icinga_host }}" { } -# vim: set syntax=icinga2 +#{# vim: set syntax=jinja2 #} vim: set syntax=icinga2 -- GitLab