Zabbix Templates Lifecycle

If you use zabbix to monitor your infrastructure and applications, you probably have a lot of templates that you affect to different servers. And maybe you have different environements, so you also have two zabbix servers (or more ?).

Well, when you update a zabbix template on the zabbix server of the test environement because the last update have changed the way you need to monitor one app, you will have to update the template in production also.

Easy, you go to templates, search the template, export it (save to My documents or whatever) and after that, you login to the zabbix in production, and load the new version of the template.

  • Do you have the history of the template ?
  • Are you able to rollback the template ?


But with ansible, you could save all the template with one command and update them to another zabbix server in one command also.


I’ve put the roles in this repository.

There is 2 roles :

  • save-tmpl-JSON
  • add-templates

The workflow is this one :

  • Work on test environement (Add templates/updates them …)
  • Test it
  • When ok, execute the below command to export templates in json files (one file per template):

    ansible-playbook -i inventories/test save-tmpl-JSON.yml

The templates will be saved in the files folder of the add-templates role.

Becarefull, if there is new templates, edit the ansible role roles/save-tmpl-JSON in order to add the new templates. At this stage, you have exported templates in json format.

You can save them with git and have a history for your templates.

Update the templates in production environment by executng this command :

ansible-playbook -i inventories/production add-templates.yml

The json templates are updated by a task in the save-tpml-JSON role. The taks is “Replace Date field by the one declared in playbook !” and replace a field named date that contains the date of the export. Not welcomed when the goal is to get the history of files. So the date is replaced by {{ version }}

Go further

Create a variable list to handle the list of templates to save. And so on for the other role. But the idea is here.