diff --git a/tasks/check.yml b/tasks/check.yml index a712bab7c79b4292d300723769b53406a3842cac..858cb6d68b04541f870b1a6493b13a8857c24fd0 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