Icinga/ansible-collection-icinga

icinga2_objects is sometimes wrongly treated as a list

Donien opened this issue · 0 comments

TLDR

We'd need to properly check that icinga2_objects from within a play's vars key is a list before trying to treat it as such.


Currently icinga2_objects - comming from a play's vars key - is collected and treated as a list
if

  • icinga2_objects is defined
  • vars['icinga2_objects'][icinga2_config_host] is not defined

This means that vars['icinga2_objects'] could be a dict and the code would try to treat it as a list as long as the current host (hostA) is not mentioned as a key to the dict.

vars:
  icinga2_objects:
    hostB:
      - ...

The above example would skipp the task at hand if currently handling hostB. But if handling hostA the task would fail due to hostA not being a key of icinga2_objects and thus the task treating icinga2_objects as a list.

---
- name: collect all config objects for myself
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 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