当前位置 主页 > 服务器问题 > win服务器问题汇总 >

    集群运维自动化工具ansible之使用playbook安装zabbix客户端

    栏目:win服务器问题汇总 时间:2019-12-05 13:46

    之前介绍了关于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