通过ansible添加主机到Zabbix 6.2失败(在6.0上工作)

通过ansible添加主机到Zabbix 6.2失败(在6.0上工作)

我在从 zabbix 6.0 到 zabbix 6.2 的转换(迁移)时遇到问题。我在 Ansible 中有一本剧本,可以自动将主机添加到 zabbix,其中包含一些预定义的 host_groups 和模板,这些在 Zabbix 6.0 上工作,但在 6.2 zabbix 中添加了 Template_groups,现在剧本抱怨它无法再找到模板了。

这是该剧本的一部分:

- name: ZABBIX - Create or update host
  local_action:
    module: community.zabbix.zabbix_host
    server_url: https://monitor.localdomain
    login_user: "a*******a"
    login_password: "S*********************y"
    host_name: "{{ ansible_hostname }}"
    visible_name: "{{ ansible_hostname }}"
    tls_psk_identity: "{{ ansible_hostname }}"
    tls_accept: 2
    tls_connect: 2
    tls_psk: "{{ psk.stdout }}"
    host_groups:
      - Linux servers
    link_templates:
      - Template OS Linux
      - Template YUM Updates
    status: enabled
    state: present
    inventory_mode: automatic
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
      - type: 2
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
        details:
          community: "{$SNMP_COMMUNITY}"
          version: 2
    proxy: "ZabbixProxy"
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
  tags:
    - zabbix-agent

这在 6.0 上完美运行,并将服务器添加到了 host_group Linux 服务器,并添加了模板 OS Linux 和 YUM 更新,没有任何问题。

现在在 6.2 中,它抱怨找不到模板,如果我对模板进行哈希处理,它会抱怨找不到 host_group。当我大声疾呼时,它抱怨它必须至少有 1 个主机组....:|

我尝试了所有模板组合,因为模板现在位于模板组中:“模板/操作系统”我什至在剧本中添加了 template_groups: 部分,因为这是 rust 中的有效字段,但显然它不适用于 ansible,因为现在它抱怨发现了无效的模块。

如何以正确的方式更改/添加模板组...?

感谢您和我一起阅读和思考。

答案1

这对我有用,我曾经delegate_to将所有请求传递给 zabbix API 服务器。并让 Ansible 管理组中每个主机的循环/分叉/并行执行。

---

- name: Update hosts in Zabbix
  hosts: "{{ groups['role_ep'] }}"
  vars_files:
    - vars/main.yaml
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    server_url: "{{ zabbix_server.fqdn }}"
    ansible_zabbix_auth_key: "{{ zabbix_server.api_key }}"
    ansible_zabbix_url_path: ''  
  tasks:

    - name: Create a new host or rewrite an existing host's info
      become: false
      delegate_to: "{{ zabbix_server.fqdn }}"
      community.zabbix.zabbix_host:
        host_name: "{{ inventory_hostname }}"
        visible_name: "{{ inventory_hostname }}"
        description: "{{ inventory_hostname }}"
        host_groups:
          - Linux servers
        link_templates:
          - Linux by Zabbix agent
          - Chassis by IPMI
        status: enabled
        state: present
        inventory_mode: manual
        # inventory_zabbix:
        #   tag: "{{ your_tag }}"
        #   alias: "{{ your_alias }}"
        #   notes: "Special Informations: {{ your_informations | default('None') }}"
        #   location: "{{ your_location }}"
        #   site_rack: "{{ your_site_rack }}"
        #   os: "{{ your_os }}"
        #   hardware: "{{ your_hardware }}"
        ipmi_authtype: -1 # default
        ipmi_privilege: 3 # operator
        ipmi_username: "{{ ipmi_username }}"
        ipmi_password: "{{ ipmi_password }}"
        interfaces:
          - type: 1
            main: 1
            useip: 0
            ip: "{{ primaryIpAddress }}"
            dns: "{{ inventory_hostname }}"
            port: "10050"
          - type: 3
            main: 1
            useip: 1
            ip: "{{ networkManagementIpAddress }}"
            dns: ""
            port: "623"
        # proxy: a.zabbix.proxy
        # macros:
        #   - macro: "{$EXAMPLEMACRO}"
        #     value: ExampleMacroValue
        #   - macro: EXAMPLEMACRO2
        #     value: ExampleMacroValue2
        #     description: Example desc that work only with Zabbix 4.4 and higher
        # tags:
        #   - tag: ExampleHostsTag
        #   - tag: ExampleHostsTag2
        #     value: ExampleTagValue

相关内容