ansible 一键安装zabbix client
目录结构
# tree ansible-zabbix-playbook
├── hosts
├── roles
│ └── zabbix
│ ├── files
│ │ └── zabbix-3.4.2.tar.gz
│ ├── tasks
│ │ └── main.yml
│ └── vars
├── zabbix.retry
└── zabbix.yml
执行命令
ansible-playbook -e server_ip=10.19.161.17 zabbix.yml -i hosts
# cat ansible-zabbix-playbook/roles/zabbix/tasks/main.yml
- name: copy
copy: src=zabbix-3.4.2.tar.gz dest=/tmp/zabbix-3.4.2.tar.gz
- name: tar zabbix
shell: cd /tmp/;tar zxf zabbix-3.4.2.tar.gz
- name: group add
shell: groupadd zabbix
- name: useradd
shell: useradd -g zabbix -s /sbin/nologin zabbix
- name: yum
yum: name={{ item }} state=latest
with_items:
- make
- gcc
- curl
- curl-devel
- pcre-devel
- name: configure
shell: cd /tmp/zabbix-3.4.2;./configure --with-net-snmp --with-libcurl --enable-agent --prefix=/usr/local/zabbix;make && make install
- name: zabbix script
shell: cp /tmp/zabbix-3.4.2/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
- name: authority
shell: chmod 755 /etc/init.d/zabbix_agentd
- name: chkconfig add
shell: chkconfig --add zabbix_agentd;chkconfig zabbix_agentd on
- name: vim zabbix_agent
shell: sed -i 's/ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_agentd"/ZABBIX_BIN="\/usr\/local\/zabbix\/sbin\/zabbix_agentd"/g' /etc/init.d/zabbix_agentd
- name: vim_conf
shell: sed -i 's/Server=127.0.0.1/Server={{ server_ip }}/g' /usr/local/zabbix/etc/zabbix_agentd.conf
- name: vim_conf
shell: sed -i "s/Hostname=Zabbix server/Hostname=$(hostname)/g" /usr/local/zabbix/etc/zabbix_agentd.conf
- name: quanxian
shell: chown -R zabbix.zabbix /usr/local/zabbix
- name: restart_server
shell: /etc/init.d/zabbix_agentd restart