ansible剧本

more /opt/shell/yaml/install_zabbix.yaml

- hosts: "{{ host }}"
  tasks:
    - name: copy zabbix-3.2.3.tar.gz
      copy: src=/ope/shell/zabbix/ dest=/data/ mode=0755
    - name: run install_zabbix.sh
      shell: bash /data/install_zabbix-agent.sh
    - name: del install_zabbix.sh
      shell: rm -rf /data/install_zabbix-agent.sh

zabbix脚本

more /opt/shell/soft/zabbix/install_zabbix.sh

#!/bin/bash
. /root/.bash_profile
yum install -y gcc
cd /usr/local/src/zabbix
groupadd zabbix
useradd zabbix -g zabbix -s /sbin/nologin
tar xzvf zabbix-3.2.3.tar.gz
cd zabbix-3.2.3
./configure --prefix=/data/zabbix --enable-agent
make
make install
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
sed -i 's!BASEDIR=/usr/local!BASEDIR=/data/zabbix!' /etc/init.d/zabbix_agentd
echo "zabbix-agent   10050/tcp      #Zabbix Agent" >>/etc/services
echo "zabbix-agent   10050/udp     #Zabbix Agent" >>/etc/services
ln -s /data/zabbix/bin/* /usr/local/bin/
ln -s /data/zabbix/sbin/* /usr/local/sbin/
cd /data/zabbix/etc
cat /dev/null >zabbix_agentd.conf
arg=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6 | awk '{print $2}' | tr -d "addr:"`
host=`hostname`
cat <> zabbix_agentd.conf
# 指定日志路径
LogFile=/tmp/zabbix_agentd.log
# 被动模式下的 Zabbix Server 地址
Server=192.168.1.100
# 主动模式下的 Zabbix Server 地址
ServerActive=192.168.1.100
ListenPort=10050
ListenIP=$arg
# 机器标识符 ( Web 界面显示的主机名称 )
Hostname=${host}_linux-azure2
# 主动注册条件,很灵活,你可以像我一样做成这种方式,两个字段完全匹配才添加主机
HostMetadata=centos
Include=/data/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1
Timeout=20
EOF
chown -R zabbix.zabbix /data/zabbix
chmod 777 /etc/sudoers
sed -i 's/Defaults    requiretty/#Defaults    requiretty/g' /etc/sudoers
echo "zabbix ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
chmod 440 /etc/sudoers
service sshd restart
service zabbix_agentd start
chkconfig zabbix_agentd on