cat /etc/ansible/zabbix/roles/http/tasks/main.yml - name: Stop Exist Zabbix Client Service In Redhat Client shell: ps -ef|grep zabbix|grep -v grep|awk '{print $2}'|xargs kill -9 >>/dev/null 2>&1 ignore_errors: yes - name: Delete Exist Zabbix Client Dir In Redhat Client shell: rm -rf {{ zabbix_dir }}/zabbix ignore_errors: yes - name: yum shell: echo "yum -y install make gcc-c++ cmake bison-devel ncurses-devel curl-devel" - name: Create Zabbix User In Redhat Client user: name={{ zabbix_user }} state=present createhome=no shell=/sbin/nologin - name: Copy Zabbix Client Software To Redhat Client copy: src=zabbix-{{ zabbix_version }}.tar.gz dest=/tmp/zabbix-{{ zabbix_version }}.tar.gz owner=root group=root - name: Uncompression Zabbix Client Software To Redhat Client shell: tar zxf /tmp/zabbix-{{ zabbix_version }}.tar.gz -C {{ zabbix_dir }}/ && rm -rf /tmp/zabbix-{{ zabbix_version }}.tar.gz - name: Copy Zabbix Start Script To Redhat Client template: src=zabbix_agentd dest=/etc/init.d/zabbix_agentd owner=root group=root mode=0755 - name: Copy Zabbix Config To Redhat Client template: src=zabbix_agentd.conf dest={{ zabbix_dir }}/zabbix/etc/zabbix_agentd.conf owner={{ zabbix_user }} group={{ zabbix_user }} mode=0644 - name: Modify file: path={{ zabbix_dir }}/zabbix owner={{ zabbix_user }} group={{ zabbix_user }} mode=0755 - name: Check Zabbix User Sudo Permission In Redhat Client shell: grep "{{ zabbix_user }}" /etc/sudoers|wc -l register: zabbix_sudoer ignore_errors: True - name: Give Sudo Permission To Zabbix User In Redhat Client shell: echo "{{ zabbix_user }} ALL=(root) NOPASSWD:/bin/netstat, /usr/bin/omreport" >> /etc/sudoers when: zabbix_sudoer.stdout|int == 0 - name: Modify shell: touch /var/log/zabbix_agentd.log && chmod -R 777 /var/log/zabbix_agentd.log && sed -i 's/^Defaults.*.requiretty/#Defaults requiretty/' /etc/sudoers - name: Start Zabbix Service In Redhat Client shell: /etc/init.d/zabbix_agentd start - name: Add Boot Start Zabbix Service In Redhat Client shell: chkconfig --level 345 zabbix_agentd on
参考 https://github.com/dl528888/ansible-examples
具体操作 http://dl528888.blog.51cto.com/2382721/1436745
zabbix_sudoer.stdout|int == 0 这个需要改下
ansible 版本1.7.2