使用ansible安裝配置zabbix客戶端

ansible角色簡介:shell

目錄名 說明
defaults 默認變量存放目錄
handlers 處理程序(當發生改變時須要執行的操做)
meta 角色依賴關係處理
tasks 具體執行的任務操做定義
templates 模板文件存放目錄
vars 變量文件目錄
files 安裝包文件目錄

 

 

 

 

 

 

 

1.查看ansible控制端目錄結構,tree /etc/ansiblecurl

/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文件內容url

- hosts: host
  roles:
  - install_zabbix_agent

3.delete_zabbix_agent.yml文件內容spa

- hosts: host
  roles:
    - delete_zabbix_agent

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

- 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.gzserver

6.拷貝zabbix_agentd啓動命令文件,到/etc/ansible/roles/install_zabbix_agent/templates/zabbix_agentd目錄,修改blog

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

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

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

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

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 文件內容rem

- 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
相關文章
相關標籤/搜索