diff --git a/changelogs/fragments/66996-zabbix-template.yaml b/changelogs/fragments/66996-zabbix-template.yaml new file mode 100644 index 00000000000..4935157f4b6 --- /dev/null +++ b/changelogs/fragments/66996-zabbix-template.yaml @@ -0,0 +1,2 @@ +bugfixes: +- zabbix_template - no longer fails with KeyError when there are no macros present in existing template (see https://github.com/ansible-collections/community.zabbix/issues/19) diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py index 8c1bdbaa9e2..8d17c859ca4 100644 --- a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py +++ b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py @@ -417,6 +417,9 @@ class Template(object): changed = True break + if 'macros' not in existing_template['zabbix_export']['templates'][0]: + existing_template['zabbix_export']['templates'][0]['macros'] = [] + if template_macros is not None: existing_macros = existing_template['zabbix_export']['templates'][0]['macros'] if template_macros != existing_macros: