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 00000000000..7ddeea37f76 --- /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/icinga2_host.py b/plugins/modules/icinga2_host.py index a740e687544..7f25c55d999 100644 --- a/plugins/modules/icinga2_host.py +++ b/plugins/modules/icinga2_host.py @@ -256,9 +256,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"] @@ -273,20 +273,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):