From ad1b26d99ebfed9fc20cd2499f16ccdeb20929c2 Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Sat, 10 Feb 2024 18:53:48 +0000 Subject: [PATCH] check ansible_host for all hosts --- tasks/check.yml | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tasks/check.yml b/tasks/check.yml index a712bab..858cb6d 100644 --- a/tasks/check.yml +++ b/tasks/check.yml @@ -17,11 +17,44 @@ - name: Icinga checks block: - - name: Each host requires a ansible_host variable to be defined + - name: "Ensure that ansible_host is defined for the icinga_master_nodes" ansible.builtin.assert: that: - - hostvars[inventory_hostname].ansible_host is defined + - hostvars[icinga_agent_node].ansible_host is defined + - hostvars[icinga_agent_node].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_agent_node + when: + - groups['icinga_master_nodes'] is defined + - groups['icinga_master_nodes'] | length > 0 + + - name: "Ensure that ansible_host is defined for the icinga_agent_nodes" + ansible.builtin.assert: + that: + - hostvars[icinga_agent_node].ansible_host is defined + - hostvars[icinga_agent_node].ansible_host is ansible.utils.ip + quiet: "{% if ansible_verbosity == 0 %}true{% else %}false{% endif %}" + loop: "{{ groups['icinga_agent_nodes'] }}" + loop_control: + loop_var: icinga_agent_node + when: + - groups['icinga_agent_nodes'] is defined + - groups['icinga_agent_nodes'] | length > 0 + + - name: "Ensure that ansible_host is defined for the icinga_remote_nodes" + ansible.builtin.assert: + that: + - hostvars[icinga_agent_node].ansible_host is defined + - hostvars[icinga_agent_node].ansible_host is ansible.utils.ip + quiet: "{% if ansible_verbosity == 0 %}true{% else %}false{% endif %}" + loop: "{{ groups['icinga_remote_nodes'] }}" + loop_control: + loop_var: icinga_agent_node + when: + - groups['icinga_remote_nodes'] is defined + - groups['icinga_remote_nodes'] | length > 0 tags: - icinga -- GitLab