From 55f0e45a3082a0129f9b0ad5d1014c8c39b0f15b Mon Sep 17 00:00:00 2001 From: Donien <88634789+Donien@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:30:07 +0200 Subject: [PATCH] Properly check if vars['icinga2_objects'] is list The previous conditions did not suffice in determining whether vars['icinga2_objects'] was a list or not. Thus the variable was sometimes treated as a list even though it was a dictionary for example. This resulted in task failures. This commit applies proper checks. Fixes #308. --- changelogs/fragments/fix_issue_308.yml | 2 ++ roles/icinga2/tasks/objects.yml | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_issue_308.yml diff --git a/changelogs/fragments/fix_issue_308.yml b/changelogs/fragments/fix_issue_308.yml new file mode 100644 index 00000000..f4b00a6a --- /dev/null +++ b/changelogs/fragments/fix_issue_308.yml @@ -0,0 +1,2 @@ +bugfixes: + - "The type of :code:`vars['icinga2_objects']` was wrongly tested for. This should be a list. The type is now `properly checked `_ for (#308)." diff --git a/roles/icinga2/tasks/objects.yml b/roles/icinga2/tasks/objects.yml index 58ac18b7..2eebb6e3 100644 --- a/roles/icinga2/tasks/objects.yml +++ b/roles/icinga2/tasks/objects.yml @@ -1,14 +1,27 @@ --- -- name: collect all config objects for myself +- name: collect all config objects for myself (from all inventory hosts) set_fact: tmp_objects: "{{ tmp_objects| default([]) + lookup('list', hostvars[item]['icinga2_objects'][icinga2_config_host]) }}" with_items: "{{ groups['all'] }}" when: hostvars[item]['icinga2_objects'][icinga2_config_host] is defined +- name: collect all config objects for myself (from myself if list) + set_fact: + tmp_objects: "{{ tmp_objects | default([]) + lookup('list', hostvars[inventory_hostname]['icinga2_objects']) }}" + when: + - hostvars[inventory_hostname]['icinga2_objects'] is defined + - hostvars[inventory_hostname]['icinga2_objects'] is iterable + - hostvars[inventory_hostname]['icinga2_objects'] is not string + - hostvars[inventory_hostname]['icinga2_objects'] is not mapping + - name: collect all config objects in play vars set_fact: tmp_objects: "{{ tmp_objects| default([]) + lookup('list', icinga2_objects) }}" - when: icinga2_objects is defined and vars['icinga2_objects'][icinga2_config_host] is not defined + when: + - icinga2_objects is defined + - icinga2_objects is iterable + - icinga2_objects is not string + - icinga2_objects is not mapping - icinga2_object: args: "{{ item }}"