码迷,mamicode.com
首页 > 其他好文 > 详细

使用ansible安装配置zabbix客户端

时间:2016-08-01 11:53:58      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

ansible角色简介:

目录名说明
defaults 默认变量存放目录
handlers 处理程序(当发生改变时需要执行的操作)
meta 角色依赖关系处理
tasks 具体执行的任务操作定义
templates 模板文件存放目录
vars 变量文件目录
files 安装包文件目录

 

 

 

 

 

 

 

1.查看ansible控制端目录结构,tree /etc/ansible

/etc/ansible/
├── ansible.cfg
├── delete_zabbix_agent.yml
├── hosts
├── install_zabbix_agent.yml
└── roles
    ├── delete_zabbix_agent
    │   ├── tasks
    │   │   └── main.yml
    │   └── vars
    │       └── main.yml
    └── install_zabbix_agent
        ├── files
        │   └── zabbix-2.2.1.tar.gz
        ├── tasks
        │   └── main.yml
        ├── templates
        │   ├── zabbix_agentd
        │   └── zabbix_agentd.conf
        └── vars
            └── main.yml
# ansible.cfg  此文件为ansible的主配置文件
# hosts        用于定义主机组
# roles        定义不同的角色
# install_zabbix_agent.yml  用于安装zabbix_agent的引导文件
# delete_zabbix_agent.yml   删除已安装的zabbix_agent的引导文件
# files 目录:用于存放将要拷贝到远程主机的安装包等
# tasks 目录:将要执行的所有任务,如果比较复杂,可以单独定义不同的任务,最后在main.yml 件中引用即可
# templates 目录:模板目录,这里存放着一些可变的文件
# vars 目录:用于存放变量

 

2.install_zabbix_agent.yml文件内容

- hosts: host
  roles:
  - install_zabbix_agent

3.delete_zabbix_agent.yml文件内容

- hosts: host
  roles:
    - delete_zabbix_agent

4./etc/ansible/roles/install_zabbix_agent/tasks/main.yml 文件内容

- name: install software
  yum: name={{item}} state=latest
  with_items:
- libcurl
- libcurl-devel - name: create zabbix user user: name={{zabbix_user}} state=present shell=/sbin/nologin - name: Uncompression Zabbix.tar.gz unarchive: src=zabbix-{{zabbix_version}}.tar.gz dest={{zabbix_dir}} - name: copy zabbix start script template: src=zabbix_agentd dest=/etc/rc.d/init.d/zabbix_agentd owner=root group=root mode=0755 - name: copy zabbix config file template: src=zabbix_agentd.conf dest={{zabbix_dir}}/zabbix/etc/zabbix_agentd.conf owner={{zabbix_user}} group={{zabbix_user}} mode=0644 - name: modify zabbix dir permission file: path={{zabbix_dir}}/zabbix owner={{zabbix_user}} group={{zabbix_user}} recurse=yes - name: start zabbix service shell: /etc/init.d/zabbix_agentd start

5.拷贝zabbix-2.2.1.tar.gz,到 /etc/ansible/roles/install_zabbix_agent/files/zabbix-2.2.1.tar.gz

6.拷贝zabbix_agentd启动命令文件,到/etc/ansible/roles/install_zabbix_agent/templates/zabbix_agentd目录,修改

 # Zabbix-Directory
        #BASEDIR=/usr/local
        BASEDIR={{zabbix_dir}}/zabbix

7.拷贝zabbix_agentd.conf配置文件,到/etc/ansible/roles/install_zabbix_agent/templates/zabbix_agentd.conf ,修改

Server={{zabbix_server_ip}}
ServerActive={{zabbix_server_ip}

8./etc/ansible/roles/install_zabbix_agent/vars/main.yml文件内容

zabbix_dir: /usr/local
zabbix_version: 2.2.1
zabbix_user: zabbix
zabbix_port: 10050
zabbix_server_ip: 10.205.16.10

9./etc/ansible/roles/delete_zabbix_agent/tasks/main.yml 文件内容

- name: Stop Zabbix_agent
  shell: pgrep zabbix_agentd | xargs kill
  ignore_errors: yes
- name: Delete Boot Start
  shell: chkconfig --del zabbix_agentd
- name: Delete Start Script
  shell: rm -rf /etc/init.d/zabbix_agentd
- name: Delete Install Dir
  shell: rm -rf {{ zabbix_dir }}/zabbix
- name: Delete Software
  shell: rm -rf {{ zabbix_dir }}/src/zabbix-{{ zabbix_version }}.tar.gz
- name: Delete Log File
  shell: rm -rf /tmp/zabbix_agentd.log
- name: Delete Zabbix User
  user: name={{ zabbix_user }} state=absent remove=yes

10./etc/ansible/roles/delete_zabbix_agent/vars/main.yml文件内容

zabbix_dir: /usr/local
zabbix_version: 2.2.1
zabbix_user: zabbix

11.执行命令安装zabbix客户端

ansible-playbook /etc/ansible/install_zabbix_agent.yml

12.执行命令删除zabbix客户端

ansible-playbook /etc/ansible/delete_zabbix_agent.yml

 

使用ansible安装配置zabbix客户端

标签:

原文地址:http://www.cnblogs.com/wsl222000/p/5724938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!