ansible 批量安装zabbix agentd客户端

 

目录结构

ansible/
├── ansible.cfg
├── hosts
├── roles
│   └── zabbix-agentd
│       ├── files
│       │   ├── install_zabbix.sh
│       │   └── zabbix-3.0.1.tar.gz
│       ├── handlers
│       ├── tasks
│       │   └── main.yml
│       └── templates
└── site.yml

 

[root@localhost ansible]# more site.yml 
---
- name: Install Zabbix-agentd
  hosts: zabbix-agentd
  remote_user: root

  roles:
    - zabbix-agentd

 

[root@localhost ansible]# more roles/zabbix-agentd/tasks/main.yml 
- name: copy zabbix_tar_gz to client
  copy: src=zabbix-3.0.1.tar.gz dest=/tmp/zabbix-3.0.1.tar.gz

- name: copy install_shell to client
  copy: src=install_zabbix.sh dest=/tmp/install_zabbix.sh

- name: install zabbix
  shell: /bin/bash /tmp/install_zabbix.sh

 

[root@localhost ansible]# more roles/zabbix-agentd/files/install_zabbix.sh 
#######client install#############
yum install -y gcc make libselinux-python


grep -q "zabbix" /etc/group
GROUP_IS=$?
if [ $GROUP_IS == 1 ];then
  groupadd zabbix
fi

grep -q "zabbix" /etc/passwd
USER_IS=$?
if [ $USER_IS == 1 ];then
  useradd -g zabbix zabbix -M -s /sbin/nologin
fi

mv /usr/local/zabbix /usr/local/zabbix_old-$(date +%Y%m%d)
rm -rf /etc/zabbix
cd /tmp
tar zxvf zabbix-3.0.1.tar.gz
cd zabbix-3.0.1
./configure --prefix=/usr/local/zabbix --enable-agent
make install
ln -s /usr/local/zabbix/etc /etc/zabbix
ln -s /usr/local/zabbix/sbin/zabbix_agentd /usr/local/sbin/
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf-$(date +%Y%m%d)

cat >/etc/zabbix/zabbix_agentd.conf<<EOF
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
Server=172.31.x.x
ServerActive=172.31.x.x
ListenPort=10050
ListenIP=0.0.0.0
EnableRemoteCommands=1
UnsafeUserParameters=1
LogFileSize=10
Timeout=30
#UserParameter=key,script
EOF

/etc/init.d/zabbix_agentd start
chkconfig zabbix_agentd on

 

 

[root@localhost ansible]# ansible-playbook site.yml

posted @ 2016-04-03 23:22  ca0guo  阅读(1671)  评论(0编辑  收藏  举报