Ansible失敗を介してZabbix 6.2にホストを追加する(6.0で動作)

Ansible失敗を介してZabbix 6.2にホストを追加する(6.0で動作)

zabbix 6.0からzabbix 6.2への変換(移行)に問題があります。いくつかの事前定義されたホストグループとテンプレートを使用して自動的にzabbixにホストを追加するAnsibleプレイブックがあります。これはZabbix 6.0で動作しましたが、6.2では、zabbixはTemplate_groupsを追加し、Playbookでテンプレートを見つけることができないと文句を言います。

これはスクリプトの一部です。

- 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で完全に機能し、サーバーをホストグループLinuxサーバーに追加し、問題なくテンプレートOS LinuxおよびYUMアップデートを追加しました。

6.2では、テンプレートが見つからないと文句を言い、テンプレートをハッシュするとホストグループが見つからないと文句を言います。私が叫んだ場合、少なくとも1つのホストグループがあるべきだと不平を言います。

テンプレートがテンプレートグループにあるので、すべてのテンプレートの組み合わせを試しました: "templates / os"プレイブックに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

おすすめ記事