Deploying Zabbix Agent on Hundreds of Servers Using Ansible
This guide explains how to use Ansible to automatically install and configure Zabbix‑agent on a large number of Linux servers, covering inventory setup, a deployment script, a playbook, execution commands, and verification of the agent listening on port 10050.
After setting up a Zabbix server, the article demonstrates how to automatically install Zabbix‑agent on dozens or hundreds of Linux hosts using Ansible.
It first shows the test environment IPs and the modification of /etc/ansible/hosts to define the inventory.
Example inventory entries:
[web] k8s-master ansible_ssh_host=192.168.20.40 k8s-node3 ansible_ssh_host=192.168.20.39The zabbix-agent.sh script is provided, which checks for the Zabbix repository, installs the agent if missing, updates the configuration file with the correct server address, and restarts the service.
#!/bin/bash
if [ ! -f /etc/yum.repos.d/zabbix.repo ]; then
rpm -ivh /root/zabbix-release-4.2-2.el7.noarch.rpm
fi
Zabbix_Agent=`rpm -qa |grep zabbix-agent|wc -l`
if [ $Zabbix_Agent -eq 0 ]; then
yum -y install zabbix-agent
fi
sed -i 's/Server=127.0.0.1/Server=192.168.20.40/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.20.40/g' /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agentThe accompanying zabbix-agent.yml playbook copies the repository RPM and the script to each host, makes the script executable, runs it, and debugs the result.
---
- hosts: all
tasks:
- name: copy zabbix-agent.repo
copy: src=/root/zabbix-release-4.2-2.el7.noarch.rpm dest=/root/
- name: install zabbix-agent
copy: src=/root/zabbix-agent.sh dest=/root/zabbix-agent.sh mode=755
- name: run script
shell: sh /root/zabbix-agent.sh
register: result
- debug: var=resultRunning ansible-playbook zabbix-agent.yml executes the deployment, and the article includes screenshots of the playbook output.
Finally, the article shows how to verify that the Zabbix‑agent is listening on port 10050 on both the server and a node using netstat -nltp | grep 10050, with additional screenshots.
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 11634/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 11634/zabbix_agentdSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
