Installing zabbix-agent with Ansible


Not only I have an puppet module for installing Zabbix, I also have some Ansible roles for this. At the moment there are 4 roles:

In this blog item, we talk about the “zabbix-agent” role. The latest version is 0.2.0.


Installing this role is very easy:

ansible-galaxy install dj-wasabi.zabbix-agent

It will be installed in your roles directory. Default is “/etc/ansible/roles” or whatever you have configured in the ansible.cfg file. After installation there is only 1 (or 2 when you make use of active items) parameters needed for making this role work:

agent_server: <IP_-_FQDN_OF_ZABBIX_SERVER>
agent_serveractive: <IP_-_FQDN_OF_ZABBIX_SERVER>

This will need the ip address or the FQDN of the “zabbix-server”.


This role works on several operating systems/families:

  • RedHat
  • Debian
  • Ubuntu
  • OpenSuse

If you have an operating system/family which isn’t in the list above, you can create an issue at the Github page and please fill in the request. I can’t make any guarantee that it will come, but I can try it. Or if you do have some Ansible skills, please create an Pull request and I would be happy to accept it. 🙂


So, how does the playbook looks like? Like this:

- hosts: all
  sudo: yes
   - role: dj-wasabi.zabbix-agent
     agent_server: <IP_-_FQDN_OF_ZABBIX_SERVER>
     agent_serveractive: <IP_-_FQDN_OF_ZABBIX_SERVER>

As you see it is very basic and does the job very good. This only installs the agent on the specific server and configures the configuration file. But we really want to automate everything right?


Few weeks ago I found this pull requests for the “ansible-modules-extra” repository. This pull requests had an few ansible modules which made sure that you can use the Zabbix API to create or update hosts configuration. In the pull requests there were something like 5 modules, but this Ansible role only use 3 of them. With this role, you can create the following:

  • host groups
  • Host itself.
  • Macros for the host

For now, when the host is created, it will only create the “zabbix interface”. Maybe with the next release I’ll make sure you can also create SNMP, JMX and IPMI interfaces.

How do we have to configure it? Something like this. You will have to change it to your environment.

- hosts: wdserver00
     - role: zabbix-agent
       zabbix_api_use: true
       zabbix_api_user: Admin
       zabbix_api_pass: Zabbix
       zabbix_create_host: present
         - Linux servers
         - Template OS Linux
         - macro_key: apache_type
           macro_value: reverse_proxy

I’ll skip the first 2 parameters, as these are described earlier on this page.

zabbix_url: The url on which the Zabbix web interface is available.
zabbix_api_user: The username which will connect to the API.
zabbix_api_pass: The password for the “zabbix_api_user” user.
zabbix_create_host: present if we want to create the host, absent if we want to delete it.
zabbix_host_groups: List of hostgroup where this host belongs to.
zabbix_link_templates: List of templates which will be linked to the host.
zabbix_macros: key, value pair of macros that will be used by the host. 

When we run Ansible, we will see at the end of the run:

.. <skip> ..
TASK: [zabbix-agent | Create hostgroups] **************************************
ok: [wdserver00 ->]

TASK: [zabbix-agent | Create a new host or update an existing host's info] ****
changed: [wdserver00 ->]

TASK: [zabbix-agent | Updating host configuration with macros] ****************
changed: [wdserver00 ->] => (item={'macro_key': 'apache_type', 'macro_value': 'reverse_proxy'})

Nice! If you check the Web interface, you’ll see that the host is created with the correct host groups and templates. If not, you’ll see some error messages in the Ansible output which will say what went wrong.

This role isn’t perfect, so if you encounter an bug or found/have and enhancement, please create an Pull request at Github and I’ll accept it. We can all make this role beter. 🙂

Side note:

There are more parameters which can be overridden, please check the “defaults/main.yml” file or the README.


8 thoughts on “Installing zabbix-agent with Ansible

  1. Hi, i got a failure after “Create hostgroups”
    failed: [ubuntu ->] => {“failed”: true}
    msg: unsupported parameter for module: host_groups

    FATAL: all hosts have already failed — aborting


    • Hi. Can you make sure that you have an “library” folder which has the file? Do you have installed on your local machine the ‘zabbix-api’?


      • Hi, thank you for the reply.

        root@ubuntu:~# find / -name zabbix_group*

        root@ubuntu:~# pip list | grep zabbix
        zabbix-api (0.4)


        • Hi,

          Sorry for late reply.
          It seems that the files in the library folder didn’t had an .py extension and was causing problems for some people. As the files now have an .py extension, could you please try again? (Please use the github version, I didn’t create an release for Galaxy yet.)


  2. I’m hitting a similar issue that module “zabbix_host” cannot be found.

    any idea how to fix that?

    TASK: [zabbix-agent | Create a new host or update an existing host’s info] ****
    fatal: [d2full06 ->] => module zabbix_host not found in configured module paths

    FATAL: all hosts have already failed — aborting

    PLAY RECAP ********************************************************************
    to retry, use: –limit @/Users/scao/zabbix-agent.retry

    d2full06 : ok=9 changed=0 unreachable=1 failed=0

    $ pip list|grep -i zabbix
    zabbix-api (0.4)
    $ python –version
    Python 2.7.6
    $ ansible –version
    ansible 1.9.2
    configured module search path = None


    • Hi,

      It seems that the files in the library folder didn’t had an .py extension and this was causing some problems for some people. Could you please try again? (Please use the github version, I didn’t create an release for Galaxy yet.)


  3. Pingback: Installing zabbix-server with ansible –

  4. Please correct the variables “agent_server” & “agent_serveractive” these are not working/deprecated.

    Please use “zabbix_agent_server” & “zabbix_agent_serveractive”

    Best regards
    Simon 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s