Adding `icinga2_objects` to inventory/host_vars does nothing
sol1-matt opened this issue · 1 comments
sol1-matt commented
Ansible version: 2.16.4
Jinja version 3.0.3
Latest galaxy version of collection
Problem
If you add icinga2_objects:
to the host_vars of a host they are ignored
In inventory/host_vars/headend.example.com/icinga2.yml
icinga2_objects:
- name: "{{ headend.api_user }}"
type: ApiUser
file: "local.d/api-users.conf"
password: "{{ headend.api_password }}"
permissions:
- "*"
Expectation
Adding icinga2_objects to a host_var will create the object on that host only
Solution
In roles/icinga2/tasks/objects.yml line 13 add the following before creating the objects
- 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
+ - name: collect all config objects in host
+ set_fact:
+ tmp_objects: "{{ tmp_objects| default([]) + lookup('list', hostvars[inventory_hostname]['icinga2_objects']) }}"
+ when: hostvars[inventory_hostname]['icinga2_objects'] is defined
+
- icinga2_object:
args: "{{ item }}"
with_items: "{{ tmp_objects }}"
with_items: "{{ result.results }}"
when: result.results is defined
mkayontour commented
Hi Matt, thanks for your PR. This is fixed in the current main branch. I just need to get a new release out. See PR #255