使用ansible-playbook自动安装zabbix agent并自动注册

本文自动化安装客户端,并自动注册。


1、安装zabbix api (自动注册需要调用API)

pip install zabbix-api

2、playbook详细

- hosts: 192.168.25.170

  remote_user: root

  tasks:

  - name: create group

    group: name=zabbix system=yes

  - name: create user

    user: name=zabbix group=zabbix system=yes

  - name: config dns

    shell: echo nameserver 8.8.8.8 > /etc/resolv.conf

  - name: install openssl

    shell:  yum -y install compat-openssl10

  - name: download agent media

    shell: rpm -ivh  http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm

  - name: copy agent config file

    copy: src=/root/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf

  - name: enable zabbix-agent

    shell: systemctl start zabbix-agent ; systemctl enable zabbix-agent ; systemctl stop firewalld

  - name: create new host

    local_action:

      module: zabbix_host

      server_url: http://192.168.25.155/zabbix/

      login_user: Admin

      login_password: zabbix

      force: yes

      host_name: "{{ ansible_default_ipv4.address}}"

      visible_name: "{{ansible_hostname}}"

      host_groups:

      - Linux servers

      link_templates:

      - Template Module ICMP Ping

      - Template OS Linux

status: enabled

      state: present

      inventory_mode: automatic

      interfaces:

      - type: 1

        main: 1

        useip: 1

        ip: "{{ ansible_default_ipv4.address}}"

        dns: ""

        port: 10050

参考:

https://blog.csdn.net/xujiamin0022016/article/details/103092560

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容