Offline Configuration of Zabbix Agent 2 using Ansible Playbooks

In this guid I will give you the steps to install zabbix-agent 2 offline and how to start using it to collect data and send it to your proxy.


  • Basic knowledge of the terminal
  • ansible server
  • A smile on your face (Put up that smile friend ?)

Firstly, you need to understand why using Ansible. Because it’s really hard and boring to install and configure each server that why we will use these technologies to make work easy also Ansible doesn’t need a lot of resources, just a host server and we will attack other servers.

code source of playbooks file here

install zabbix agent 2

For many reasons of security, we avoid allowing internet servers so that why we will install a zabbix-agent 2 and put it in /tmp.

On host server:

cd /tmp

Now in Ansible directory we will set up a playbook to install the agent in other servers:

cd /etc/ansible
nano playbook1.yml

And we will put this script yaml to install the agent:

- hosts: all
  become: true
    - name: Copy local zabbix package to target servers
        src: /tmp/zabbix-release_6.2-4+ubuntu20.04_all.deb
        dest: /tmp/
    - name: Install zabbix repo from local repository
        deb: /tmp/zabbix-release_6.2-4+ubuntu20.04_all.deb
        state: present

    - name: Update package cache
        update_cache: yes

    - name: Install zabbix agent
        name: zabbix-agent2
        state: present

    - name: Start service zabbix-agent2
      become: yes
          name: zabbix-agent2
          state: started

After that we launch this command to start the installation:

ansible-playbook playbook1.yml

Now we should setup our agent to start collecting information.
So in /etc/zabbix/zabbix_agent2.conf we should put this information to connect the agent to the proxy, but don’t worry all this will be with Ansible.

Let create a file on the host server and put this configuration and send it to all your clients servers:

mkdir /templates
nano zabbix_agent2.conf.j2
#copy and past on zabbix_agent2.conf.j2
Hostname={{ ansible_hostname }}

And now we will create a new playbook in /etc/Ansible to send this configuration and start the service:

nano playbook2.yml
- hosts: all
  gather_facts: yes
      - name: Remove zabbix config file
        become: yes
            path: /etc/zabbix/zabbix_agent2.conf
            state: absent

      - name: Create new zabbix config file from template
        become: yes
            src: "/templates/zabbix_agent2.conf.j2"
            dest: "/etc/zabbix/zabbix_agent2.conf"

      - name: Start service zabbix-agent
        become: yes
            name: zabbix-agent2
            state: started
ansible-playbook playbook2.yml

Now you are done and the agent installed in all your clients servers.

Remember that you could use Ansible with a lot of things and for more examples check here