Note: This article relates to ansible after version
2.5.0
and zabbix version 3.4, but presumably works with version 4.0
Prerequisites for this tutorial
The prerequisites for this tutorial are a working zabbix server, version 3.4 or greater, and you should have to hand the zabbix web gui URL, and login details for that instance. If you haven’t yet setup a zabbix server, we provide an ansible role for this task, and this is available from galaxy here.
Your fresh instance of zabbix should look something like this:
XXXX
You should also have a working ansible installation, and be familiar with the basic ansible cli commands.
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.
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.
Hosts
So when run, this playbook will run first against the zabbix server, and then
once for each Host in the ansible hostgroup zabbix_hosts
. What we want the
result of that to be, is that each hosts registers in zabbix, and for that we
can use the zabbix_host
module like so;
once you run this playbook, you should expect to see each of the hosts in the zabbix_hosts ansible group appear in the zabbix gui under the configuration tab: