jenkins ansible 附zabbix_agent批量安装示例
插件:Ansible plugin
一、ansible ad-hoc command


二、ansible-playbook
批量部署zabbix-agent示例:

playbook 目录及文件组成
[root@bogon zabbix]# cat zabbix1.yml
- hosts: zabbix-agent
roles:
- { role: init }
- { role: zabbix }
[root@bogon zabbix]# cat host [eee] 10.20.200.47:2702 ansible_ssh_user=hzcfroot [zabbix-agent] 10.10.10.14 ansible_ssh_port=2702 10.10.10.16 ansible_ssh_port=2702
[root@bogon zabbix]# tree roles/
roles/
├── init
│ ├── files
│ ├── handlers
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ └── vars
└── zabbix
├── files
│ └── zabbix-3.2.7.tar.gz
├── handlers
│ └── main.yaml
├── tasks
│ └── main.yml
├── templates
│ └── zabbix_agentd.conf
└── vars
└── main.yml
12 directories, 6 files
[root@bogon zabbix]# cat roles/init/tasks/main.yml
---
- name: install dependency packs
yum: name={{ item }} state=latest
with_items:
- curl-devel
- name: add user
user:
name: zabbix
shell: /bin/bash
state: present
[root@bogon zabbix]# cat roles/zabbix/tasks/main.yml
---
#- name: copy zabbix
# copy: src={{ item.src }} dest={{ item.dest }}
# with_items:
# - { src: zabbix-3.2.7.tar.gz , dest: /opt/zabbix-3.2.7.tar.gz }
- name: unarchive
unarchive:
src=/root/zabbix-3.2.7.tar.gz
dest=/opt/
copy=yes
- name: install
shell: chdir={{ dir_root }} ./configure --prefix=/usr/local/zabbix --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 && make && make install
- name: copy file
template: src=zabbix_agentd.conf dest=/usr/local/zabbix/etc/zabbix_agentd.conf owner=root group=root mode=644
- name: start agent
shell: /usr/local/zabbix/sbin/zabbix_agentd
[root@bogon zabbix]# cat roles/zabbix/templates/zabbix_agentd.conf |grep -v "^$\|^#"
LogFile=/tmp/zabbix_agentd.log
Server=10.10.10.11
ServerActive=10.10.10.11
Hostname={{ inventory_hostname }}
HostMetadataItem=system.uname
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1
[root@bogon zabbix]# cat roles/zabbix/vars/main.yml dir_root: /opt/zabbix-3.2.7
[root@bogon zabbix]# ls roles/zabbix/files/ zabbix-3.2.7.tar.gz
执行结果:
[test_ansible_maven] $ ansible-playbook /etc/ansible/zabbix/zabbix1.yml -i /etc/ansible/zabbix/host -l zabbix-agent -f 5 --private-key /root/apache-tomcat/temp/ssh2148971613044433366.key -u root channel stopped PLAY [zabbix-agent] ************************************************************ TASK [Gathering Facts] ********************************************************* ok: [10.10.10.14] ok: [10.10.10.16] TASK [init : install dependency packs] ***************************************** changed: [10.10.10.16] => (item=[u'curl-devel']) changed: [10.10.10.14] => (item=[u'curl-devel']) TASK [init : add user] ********************************************************* changed: [10.10.10.14] changed: [10.10.10.16] TASK [zabbix : unarchive] ****************************************************** changed: [10.10.10.14] changed: [10.10.10.16] TASK [zabbix : install] ******************************************************** changed: [10.10.10.16] changed: [10.10.10.14] TASK [zabbix : copy file] ****************************************************** changed: [10.10.10.16] changed: [10.10.10.14] TASK [zabbix : start agent] **************************************************** changed: [10.10.10.14] changed: [10.10.10.16] PLAY RECAP ********************************************************************* 10.10.10.14 : ok=7 changed=6 unreachable=0 failed=0 10.10.10.16 : ok=7 changed=6 unreachable=0 failed=0 Finished: SUCCESS

浙公网安备 33010602011771号