Skip to content

Instantly share code, notes, and snippets.

@gustavomcarmo
Created July 25, 2018 07:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gustavomcarmo/1683929579f1029c7f9c194d79ee8fa2 to your computer and use it in GitHub Desktop.
Save gustavomcarmo/1683929579f1029c7f9c194d79ee8fa2 to your computer and use it in GitHub Desktop.
Example of Ansible playbook for installing and configuring the Zabbix agent in a host and then creating the host in a Zabbix server.
---
- name: Install the Zabbix agent
yum:
name: http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.8-1.el7.x86_64.rpm
- name: Configure the Zabbix agent
replace:
path: /etc/zabbix/zabbix_agentd.conf
regexp: '{{item.regexp}}'
replace: '{{item.replace}}'
with_items:
- {regexp: "^Server=127.0.0.1$", replace: "Server={{zabbix_server}}"}
- {regexp: "^ServerActive=127.0.0.1$", replace: "ServerActive={{zabbix_server}}"}
- {regexp: "^Hostname=Zabbix server$", replace: "Hostname={{ansible_hostname}}"}
vars:
- zabbix_server: zabbix-server.brazilsouth.cloudapp.azure.com
- name: Start the Zabbix agent service
service:
name: zabbix-agent
state: started
enabled: yes
- name: Create a new host or update an existing host's info
local_action:
module: zabbix_host
server_url: http://zabbix-server.brazilsouth.cloudapp.azure.com
login_user: zabbix-admin
login_password: zabbix-admin-password
host_name: '{{ansible_hostname}}'
host_groups:
- Virtual machines
- Azure - Cluster Kubernetes
link_templates:
- Template OS Linux
- Template App Docker
interfaces:
- type: 1
main: 1
useip: 1
ip: '{{ansible_ssh_host}}'
dns: ""
port: 10050
@rafa0184
Copy link

rafa0184 commented Nov 8, 2022

Do you see this error, using zabbix 5?
fatal: [webserver -> localhost]: FAILED! => {"changed": false, "msg": "Failed to connect to Zabbix server: urllib2.URLError - Not Found"}

@gustavomcarmo
Copy link
Author

It seems you didn't set your Zabbix server correctly in server_url. Check also if your local machine can really access the URL defined in server_url.

@rafa0184
Copy link

Gustavo thanks, the script is running right now.
This problem happened cause my zabbix has a url redirection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment