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

  

转载于:https://www.cnblogs.com/FRESHMANS/p/8204721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值