Note: This article relates to ansible after version 2.5.0 and zabbix version 3.4, but presumably works with version 4.0

So here we dive into actually configuring the hosts, templates, users, and alerts that we need for a useful monitoring setup with ansible and zabbix.

The configuration is split into 2 parts, and so we use 2 plays. One for general configuration that is applied to the server, and the second for host specific configuration. The general configuration only needs to be done once, and not for every host.

So initially we will create a file like so, with a section for configuring the server, and section which is run for each host to be monitored.

---

- hosts: zabbix
  become: true
  tasks:
    - import_role:
        name: limepepper.zabbix-server

- hosts: zabbix_hosts
  tasks:
    - import_role:
        name: limepepper.zabbix-agent

If you run this with ansible-playbook it will import the zabbix-server modules and install zabbix agent on each of the hosts.

You can check each host has zabbix-agent running, but as we have not configured auto-discovery, we do not expect the hosts to exist in the server console yet.

Users

There are 2 main purposes for user objects in a monitoring system.

  1. User logins to UI
  2. As a destination for notifications. e.g. Email, pager

The users will be configured on the zabbix server, and ansible will make calls to the zabbix API address, so this must be modified to match the situation.

---

- hosts: zabbix
  become: true
  tasks:
    - import_role:
        name: limepepper.zabbix-server

- hosts: zabbix_hosts
  tasks:
    - import_role:
        name: limepepper.zabbix-agent