diff --git a/changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml b/changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml new file mode 100644 index 0000000000..7ddeea37f7 --- /dev/null +++ b/changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml @@ -0,0 +1,2 @@ +bugfixes: + - "icinga2_host - fix the data structure sent to Icinga to make use of host templates and template vars (https://github.com/ansible-collections/community.general/pull/6286)." diff --git a/plugins/modules/monitoring/icinga2_host.py b/plugins/modules/monitoring/icinga2_host.py index 0f4e2b26a0..ee357e896f 100644 --- a/plugins/modules/monitoring/icinga2_host.py +++ b/plugins/modules/monitoring/icinga2_host.py @@ -250,9 +250,9 @@ def main(): state = module.params["state"] name = module.params["name"] zone = module.params["zone"] - template = [name] + template = [] if module.params["template"]: - template.append(module.params["template"]) + template = [module.params["template"]] check_command = module.params["check_command"] ip = module.params["ip"] display_name = module.params["display_name"] @@ -267,20 +267,18 @@ def main(): module.fail_json(msg="unable to connect to Icinga. Exception message: %s" % (e)) data = { + 'templates': template, 'attrs': { 'address': ip, 'display_name': display_name, 'check_command': check_command, 'zone': zone, - 'vars': { - 'made_by': "ansible", - }, - 'templates': template, + 'vars.made_by': "ansible" } } - if variables: - data['attrs']['vars'].update(variables) + for key, value in variables.items(): + data['attrs']['vars.' + key] = value changed = False if icinga.exists(name):