ansible-playbook调用zabbix-api自动添加主机

本是古典 何须时尚 2022-05-11 00:56 319阅读 0赞

ansible-playbook调用zabbix-api自动添加主机

  1. playbook-example

    example.yml


    • hosts: “{
      { host }}”
      vars:
      zabbix_host_groups: “{
      { host }}”

      zabbix_url: “http://zabbix.example.com“
      zabbix_api_user: Admin
      zabbix_api_pass: admin
      zabbix_api_create_hostgroup: True
      zabbix_api_create_hosts: True
      zabbix_create_hostgroup: present # or absent
      zabbix_create_host: present # or absent
      zabbix_host_status: enabled
      zabbix_agent_hostname: “{
      { ansible_hostname }}”
      zabbix_proxy: null
      zabbix_inventory_mode: disabled
      zabbix_useuip: 1
      zabbix_agent_service: zabbix-agent
      dns_name: null

      zabbix_link_templates:

      1. - Template OS Linux Active

      zabbix_agent_interfaces:

      1. - type: 1
      2. main: 1
      3. useip: "{

      { zabbix_useuip }}”

      1. ip: 0.0.0.0
      2. dns: ""
      3. port: 0

      tasks:

      • name: “Make sure the zabbix-agent service is running”
        service:
        name: “{
        { zabbix_agent_service }}”
        state: started
        enabled: yes
        tags:

        • service
      • name: “Create hostgroups”
        local_action:
        module: zabbix_group
        server_url: “{
        { zabbix_url }}”
        login_user: “{
        { zabbix_api_user }}”
        login_password: “{
        { zabbix_api_pass }}”
        host_group: “{
        { zabbix_host_groups }}”
        state: “{
        { zabbix_create_hostgroup }}”
        when:

        • zabbix_api_create_hostgroup
          tags:
        • api
      • name: “Create a new host or update an existing host’s info”
        localaction:
        module: zabbix_host
        server_url: “{
        { zabbix_url }}”
        login_user: “{
        { zabbix_api_user }}”
        login_password: “{
        { zabbix_api_pass }}”
        host_name: “{
        { zabbix_agent_hostname }}”
        host_groups: “{
        { zabbix_host_groups }}”
        link_templates: “{
        { zabbix_link_templates }}”
        status: “{
        { zabbix_host_status }}”
        state: “{
        { zabbix_create_host }}”
        proxy: “{
        { zabbix_proxy }}”
        inventory_mode: “{
        { zabbix_inventory_mode }}”
        interfaces: “{
        { zabbix_agent_interfaces }}”
        visible_name: “{
        { zabbix_host_groups }}
        {
        { inventory_hostname }}”
        when:

        • zabbix_api_create_hosts
          changed_when: false
          tags:
        • api
    • 执行playbook

    ansible-playbook -i hosts auto_add_hosts_to_zabbix_server.yml -e host=appname

注意:笔者的zabbix-agent是主动模式,如果被动模式需更改: zabbix_agent_interfaces:

发表评论

表情:
评论列表 (有 0 条评论,319人围观)

还没有评论,来说两句吧...

相关阅读

    相关 esxi主机添加缓存配置

    一台联想sr650安装了esxi6.7,配了一块ssd硬盘做缓存加速(加速写) 官方文档里描述: 主机级缓存由低延迟磁盘上的文件组成,ESXi将该磁盘用作虚拟机交换文件的