集群运维自动化工具集群运维自动化工具ansible之使用之使用playbook安装安装zabbix客户端客户端
Zabbix客户端的安装配置:Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数,保证服务器系统的安全运
营;本文讲述的是使用playbook安装zabbix客户端。
之前介绍了关于ansible的安装与使用(包括模块与playbook使用,地址是//www.jb51.net/article/52154.htm),今天介绍一下如何使用playbook来部署zabbix客户端。
ansible服务端的环境为centos 6.5 x86_64系统
ansible客户端环境为centos 6.3 x86_64系统
目前我的playbook只允许centos或redhat 6系列系统来安装zabbix客户端,并且客户端的版本是2.0.6.
下面是playbook的结构
14:29:30 # pwd
/etc/ansible/roles
root@ip-10-10-10-10:/etc/ansible/roles
14:29:37 # tree zabbix_client_*
zabbix_client_delete 删除已经安装的zabbix客户端
├── files 存放文件的
├── handlers 重启的东东
├── meta galaxy_info的信息
│ └── main.yml
├── tasks 操作的任务流程
│ ├── delete.yml
│ └── main.yml
├── templates 模板
└── vars 变量
└── main.yml
zabbix_client_install
├── files
│ └── zabbix-2.0.6.tar.gz
├── handlers
├── meta
│ └── main.yml
├── tasks
│ ├── copy.yml
│ ├── delete.yml
│ ├── install.yml
│ └── main.yml
├── templates
│ ├── zabbix_agentd
│ └── zabbix_agentd.conf
└── vars
└── main.yml
12 directories, 13 files
下面是先介绍一下安装方面zabbix_client_install的内容
1、galaxy_info的信息
14:32:15 # cat /etc/ansible/roles/zabbix_client_install/meta/main.yml
galaxy_info:
author: Deng Lei
description: Install Zabbix Client
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Monitor
dependencies: []
2、task里的copy.xml信息
14:33:35 # cat /etc/ansible/roles/zabbix_client_install/tasks/copy.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
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Delete Exist Zabbix Client Dir In Redhat Client
shell: rm -rf {{ zabbix_dir }}/zabbix
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Install Base Require Software In Redhat Client
yum: name={{ item }} state=latest
with_items:
- telnet
- dmidecode
- tar
- name: Create Zabbix User In Redhat Client
user: name={{ zabbix_user }} state=present createhome=no shell=/sbin/nologin
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- 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
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Uncompression Zabbix Client Software To Redhat Client
shell: tar zxf /tmp/zabbix-{{ zabbix_version }}.tar.gz -C {{ zabbix_dir }}/
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Copy Zabbix Start Script To Redhat Client
template: src=zabbix_agentd dest=/etc/init.d/zabbix_agentd owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Copy Zabbix Config To Redhat Client
template: src=zabbix_agentd.conf dest={{ zabbix_dir }}/zabbix/conf/zabbix_agentd.conf owner={{ zabbix_user }} group={{ zabbix_user }} mode=0644
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
此文件是复制对应的文件到客户端
3、task的install.yml信息
14:34:26 # cat /etc/ansible/roles/zabbix_client_install/tasks/install.yml
- name: Modify Zabbix Dir Permission In Redhat Client
file: path={{ zabbix_dir }}/zabbix owner={{ zabbix_user }} group={{ zabbix_user }} mode=0755
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Check Zabbix User Sudo Permission In Redhat Client
shell: grep "{{ zabbix_user }}" /etc/sudoers|wc -l
register: zabbix_sudoer
ignore_errors: True
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- 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: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6 and zabbix_sudoer|int ==0
- name: Start Zabbix Service In Redhat Client
shell: /etc/init.d/zabbix_agentd start
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
- name: Add Boot Start Zabbix Service In Redhat Client
shell: chkconfig --level 345 zabbix_agentd on
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
此文件主要是安装
4、tasks的delete.yml信息
14:35:08 # cat /etc/ansible/roles/zabbix_client_install/tasks/delete.yml
- name: Delete Zabbix compression Software In Redhat Client