Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a new template to an existing host #1413

Open
olistu opened this issue Oct 31, 2024 · 4 comments
Open

How to add a new template to an existing host #1413

olistu opened this issue Oct 31, 2024 · 4 comments

Comments

@olistu
Copy link

olistu commented Oct 31, 2024

Hi all,

I run the following playbook to add a new template to an existing host but without success.

The playbook:
`- name: Set variables
set_fact:
zabbix_api_token: 60460362b83e4407f76863c40c60f082c375d0ddccdd220108c246f0efc26e2e
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: true
ansible_host: zabbix.server.ch
ansible_zabbix_url_path: monitoring

  • name: Set API token
    set_fact:
    ansible_zabbix_auth_key: "{{ zabbix_api_token }}"

  • name: Add template UNIFR RedHat to '{{ var_hosts }}'
    community.zabbix.zabbix_host:
    host_name: "{{ var_hosts }}"
    link_templates:
    - "UNIFR RedHat"
    delegate_to: localhost`

My error :
"msg": "connection error occurred: REST API returned {'code': -32602, 'message': 'Invalid params.', 'data': 'Incorrect arguments passed to function.'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"host.update\", \"id\": \"8a7590a9-dfd8-4eda-8ea9-14a7e3f51744\", \"params\": {\"hostid\": \"10667\", \"groups\": [{\"groupid\": \"2\"}], \"status\": 0, \"monitored_by\": 0, \"interfaces\": [{\"main\": 1, \"useip\": 1, \"ip\": \"134.21.83.154\", \"dns\": \"\", \"port\": \"10050\", \"interfaceid\": \"97\", \"hostid\": \"10667\", \"type\": 1, \"available\": \"1\", \"error\": \"\", \"errors_from\": \"0\", \"disable_until\": \"0\", \"details\": {\"version\": 2, \"bulk\": 1, \"community\": \"\", \"securityname\": \"\", \"contextname\": \"\", \"securitylevel\": 0, \"authprotocol\": 0, \"authpassphrase\": \"\", \"privprotocol\": 0, \"privpassphrase\": \"\"}}]}, \"auth\": \"60460362b83e4407f76863c40c60f082c375d0ddccdd220108c246f0efc26e2e\"}",

What is wrong ?
I need help.
Regards
Olivier

@masa-orca
Copy link
Collaborator

Let me know community.zabbix collection version which you use.

@olistu
Copy link
Author

olistu commented Nov 5, 2024

Let me know community.zabbix collection version which you use.

the following version : community.zabbix 3.0.4

@masa-orca
Copy link
Collaborator

Please use version 3.1.2.

@StefanIGit
Copy link

hi this is my "workaround"

    - name: Get existing host infos from Zabbix Server
      community.zabbix.zabbix_host_info:
        host_name: "{{ inventory_hostname }}"
        host_ip: "{{ hostvars[inventory_hostname]['ansible_host'] }}"
        exact_match: true
        remove_duplicate: true
      register: host_infos

    - name: Add existing template to existing list
      # ansible example: create list from loop
      ansible.builtin.set_fact:
        new_templates: |-
          [
          {% for item in host_infos.hosts[0].parentTemplates %}
            "{{ item.name }}",
          {% endfor %}
          ]

    - name: Add new template to existing list if missing
      when: "zabbix_template_name not in new_templates"
      ansible.builtin.set_fact:
        new_templates: "{{ new_templates + [zabbix_template_name] }}"

    - name: Update existing host to add new templates on Zabbix Server
      community.zabbix.zabbix_host:
        host_name: "{{ inventory_hostname }}"
        link_templates: "{{ new_templates }}"
        status: enabled

could be improved by something like "when: host_infos..." to make sure we got then and for the correct host too ;)
NOT sure who this behaves with other parameters and it my reapply all template a new with enabled trigger which have been manually disabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants