1. ansible-playbook自动化部署zabbix-server的yaml文件
[root@localhost ansible]# cat zabbix_server.yml
---
- hosts: zabbix_server
tasks:
- name: "推送zabbix repo源"
copy: src=zabbix_Aliyun.repo dest=/etc/yum.repos.d/
- name: "安装zabbix服务端所需组件"
yum: name=mariadb,mariadb-server,zabbix-server-mysql,zabbix-web-mysql,zabbix-agent,httpd state=latest
- name: "启动数据库"
systemd: name=mariadb state=started
- name: "创建zabbix数据库"
shell: mysql -e "create database zabbix charset utf8;"
- name: "给zabbix用户授权"
shell: mysql -e "grant all on zabbix.* to 'zabbix'@'localhost' identified by '123';"
- name: "导入zabbix的初始数据到数据库中"
shell: zcat /usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz | mysql zabbix
- name: "推送zabbix-server的配置文件"
copy: src=zabbix_server.conf dest=/etc/zabbix
- name: "配置PHP的时区"
copy: src=zabbix.conf dest=/etc/httpd/conf.d
- name: "启动所有服务"
systemd: name={{ item }} state=started enabled=yes
with_items:
- httpd
- zabbix-server
- zabbix-agent
[root@localhost ansible]#
2. ansible-playbook自动化部署zabbix-agent的yaml文件
[root@localhost ansible]# cat zabbix_agent.yml
---
- hosts: zabbix_agent
tasks:
- name: "推送zabbix repo源"
copy: src=zabbix_Aliyun.repo dest=/etc/yum.repos.d/
- name: "安装zabbix客户端"
yum: name=zabbix-agent state=latest
- name: "推送zabbix客户端配置文件"
copy: src=zabbix_agentd.conf dest=/etc/zabbix/
notify:
- restart_agent
handlers:
- name: "restart_agent"
systemd: name=zabbix-agent state=restarted
[root@localhost ansible]#
3. 参考文章
Centos7 安装zabbix4.2
https://blog.csdn.net/m0_46674735/article/details/110954103