# How to add a new template to an existing host

**URL:** <https://forum.ansible.com/t/how-to-add-a-new-template-to-an-existing-host/10622>\
**Category:** Get Help\
**Tags:** playbook, documentation, collections\
**Created:** [October 31, 2024, 7:00pm UTC](https://forum.ansible.com/t/how-to-add-a-new-template-to-an-existing-host/10622 "2024-10-31T19:00:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Studer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/olivier_studer/32/5310_2.png) [@Olivier\_Studer](https://forum.ansible.com/u/Olivier_Studer)\
**Post date:** [October 31, 2024, 7:00pm UTC](https://forum.ansible.com/t/how-to-add-a-new-template-to-an-existing-host/10622/1 "2024-10-31T19:00:58Z")

</div>

Hi all,

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

The playbook:

```auto
- 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 :

```auto
"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

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [November 1, 2024, 8:44am UTC](https://forum.ansible.com/t/how-to-add-a-new-template-to-an-existing-host/10622/2 "2024-11-01T08:44:10Z")

</div>

Welcome to the forum, @Olivier_Studer!

The examples in the [community.zabbix.zabbix\_host](https://docs.ansible.com/ansible/latest/collections/community/zabbix/zabbix_host_module.html) collection are not super intuitive, but this should work:

```yaml
- name: Add template UNIFR RedHat to '{{ var_hosts }}'
  community.zabbix.zabbix_host:
    host_name: "{{ var_hosts }}"
    link_templates:
      - "UNIFR RedHat"
  delegate_to: zabbix.server.ch
  vars:
    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
    ansible_zabbix_auth_key: 60460362b83e4407f76863c40c60f082c375d0ddccdd220108c246f0efc26e2e

```

However, you might want to add the zabbix host to your inventory

```yaml
$ cat ansible-inventory/host_vars/zabbix-server.yml
---
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
ansible_zabbix_auth_key: 60460362b83e4407f76863c40c60f082c375d0ddccdd220108c246f0efc26e2e 

```

so you don’t have to specify all those variables in your playbook for every zabbix related task:

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

```

You should also consider encrypting the api token with [ansible vault](https://docs.ansible.com/ansible/latest/vault_guide/index.html).
