使用ansible-playbook部署zabbix-agent-4.0

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用ansible-playbook部署zabbix-agent-4.0相关的知识,希望对你有一定的参考价值。

- hosts: all
  remote_user: root
  tasks:
  - name:  CentOS6 system copy zabbix-agent rpm
    copy: src=/tmp/zabbix-agent-3.4.9-1.el6.x86_64.rpm dest=/tmp/zabbix-agent-3.4.9-1.el6.x86_64.rpm
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "6" 
  - name:  CentOS7 system copy zabbix-agent rpm
    copy: src=/tmp/zabbix-agent-3.4.9-1.el7.x86_64.rpm dest=/tmp/zabbix-agent-3.4.9-1.el7.x86_64.rpm
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "7"
  - name: yum install zabbix-agent
    shell: cd /tmp;yum -y localinstall zabbix-agent-3.4.*.rpm
  - name: rm zabbix-agent
    shell: cd /tmp;rm -rf zabbix-agent-3.*.rpm
  - name: configure Server IP
    shell: sed -i ‘s/Server=127.0.0.1/Server=192.168.58.58/‘ /etc/zabbix/zabbix_agentd.conf  
  - name: configure ServerActive IP
    shell: sed -i ‘s/ServerActive=127.0.0.1/ServerActive=192.168.58.58/‘ /etc/zabbix/zabbix_agentd.conf
  - name: configure HostMetadata
    shell: sed -i ‘s/# HostMetadata=/HostMetadata=qas/‘ /etc/zabbix/zabbix_agentd.conf
  - name: CentOS6 system configure Hostname
    shell: host=`ifconfig |awk -F ‘[ :]+‘ ‘NR==2 {print $4}‘`;sed -i ‘s/Hostname=Zabbix server/Hostname=‘$host‘/‘ /etc/zabbix/zabbix_agentd.conf
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "6"
  - name: CentOS7 system configure Hostname
    shell: host=`ifconfig |awk -F ‘[ :]+‘ ‘NR==2 {print $3}‘`;sed -i ‘s/Hostname=Zabbix server/Hostname=‘$host‘/‘ /etc/zabbix/zabbix_agentd.conf
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "7"
  - name: CentOS6 system start zabbix
    shell: /etc/init.d/zabbix-agent start;chkconfig zabbix-agent on
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "6"
  - name: CentOS7 system start zabbix
    shell: systemctl enable zabbix-agent.service;systemctl restart zabbix-agent.service
    when:
      - ansible_distribution == "CentOS"
      - ansible_distribution_major_version == "7"

git仓库地址

https://github.com/xgh2016/ansible-zabbix

以上是关于使用ansible-playbook部署zabbix-agent-4.0的主要内容,如果未能解决你的问题,请参考以下文章

使用ansible-playbook部署zabbix-agent-4.0

Ansible-playbook实现Apache(httpd)编译安装及批量部署

Ansible-playbook tomcat部署

[Docker][ansible-playbook]3 持续集成环境初探

Ansible-playbook自动部署MySQL主从

ansible-playbook 部署tomcat简单示例