Ansible部署zabbix-agent

playbook目录

zabbix/
├── hosts             ##定义的主机列表
├── install_zabbix_agent.yml          ##安装入口文件
└── roles
    ├── install_zabbix_agent
       ├── files
       │   ├── zabbix-release-3.2-1.el7.noarch.rpm
       │   └── zabbix-release_3.2-1+trusty_all.deb
       ├── tasks
       │   └── main.yml            ##安装文件
       ├── templates
       │   ├── zabbix-agentd.conf.j2
       │   └── zabbix-agentd.conf.j2.bak
       └── vars
           └── main.yml

install_zabbix_agent.yml

- hosts: xiaozhan
  roles:
  - install_zabbix_agent
  vars:
  - zabbix_centos: zabbix-release-3.2-1.el7.noarch.rpm
  - zabbix_ubuntu: zabbix-release_3.2-1+trusty_all.deb

roles/install_zabbix_agent/tasks/main.yml

- name: copy zabbix file
  copy: src={{ zabbix_centos }} dest=/root/
  when: ansible_distribution == 'CentOS'
- name: rpm -ivh zabbix-agent
  shell: rpm -ivh /root/{{ zabbix_centos }}
  when: ansible_distribution == 'CentOS'
- name: install zabbix-agent
  shell: yum -y install zabbix-agent
  when: ansible_distribution == 'CentOS'
- name: copy zabbix-agent.conf
  template: src=zabbix-agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
  when: ansible_distribution == 'CentOS'
- name: start zabbix-agent
  shell: systemctl start zabbix-agent
  when: ansible_distribution == 'CentOS'
- name: copy  zabbix file
  copy: src={{ zabbix_ubuntu }} dest=/root/
  when: ansible_distribution == 'Ubuntu'
- name: install zabbix
  shell: dpkg -i /root/{{ zabbix_ubuntu }}
  when: ansible_distribution == 'Ubuntu'
- name: apt-get update
  shell: apt-get update
  when: ansible_distribution == 'Ubuntu'
- name: install zabbix
  shell: apt-get install zabbix-agent
  when: ansible_distribution == 'Ubuntu'
- name: copy zabbix-agent.conf
  template: src=zabbix-agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
  when: ansible_distribution == 'Ubuntu'
- name: start zabbix
  service: name=zabbix-agent state=restarted
  when: ansible_distribution == 'Ubuntu'

roles/install_zabbix_agent/templates/zabbix-agentd.conf.j2

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=serverip
ServerActive=serverip
HostnameItem=system.hostname   ##自动获取主机名
Include=/etc/zabbix/zabbix_agentd.d/

roles/install_zabbix_agent/vars/main.yml

zabbix_server_ip: *.*.*.*

执行

ansible-playbook -i hosts install_zabbix_agent.yml

 

 

 

转载于:https://www.cnblogs.com/Z-style/p/7279476.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值