# Template variable and host file

**URL:** <https://forum.ansible.com/t/template-variable-and-host-file/8454>\
**Category:** Get Help\
**Created:** [September 12, 2024, 7:11am UTC](https://forum.ansible.com/t/template-variable-and-host-file/8454 "2024-09-12T07:11:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca219](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/luca219/32/2154_2.png) [@luca219](https://forum.ansible.com/u/luca219)\
**Post date:** [September 12, 2024, 7:11am UTC](https://forum.ansible.com/t/template-variable-and-host-file/8454/1 "2024-09-12T07:11:41Z")

</div>

I use ansible to send update command in my devices.  
To complete this task I might specific serial number.  
I would set or ansible\_host in my template.yml or set serial\_number in my ansible\_host in host file.  
I can’t find the correct syntax to specific this, can someone give me help?  
best regards.

**----tempalete.yml**

- hosts: devices  
collections:  
serial: xyz  
ansible\_host: host1  
**---- host file**  
[devices]  
host1 ansible-host=x.y.z.k

---

<div class="post-metadata">

**Author:** ![RayJin2000](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rayjin2000/32/3641_2.png) [@RayJin2000](https://forum.ansible.com/u/RayJin2000)\
**Post date:** [September 13, 2024, 8:48am UTC](https://forum.ansible.com/t/template-variable-and-host-file/8454/2 "2024-09-13T08:48:42Z")

</div>

You should create a group\_vars folder for your Hosts and add the vars there:  
[https://docs.ansible.com/ansible/latest/inventory\_guide/intro\_inventory.html#organizing-host-and-group-variables](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#organizing-host-and-group-variables)

Have a look at my updated examples Repo: [ansible-examples/lamp\_simple at master · RayJin2000/ansible-examples · GitHub](https://github.com/RayJin2000/ansible-examples/tree/master/lamp_simple)

---

<div class="post-metadata">

**Author:** ![luca219](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/luca219/32/2154_2.png) [@luca219](https://forum.ansible.com/u/luca219)\
**Post date:** [September 13, 2024, 9:38am UTC](https://forum.ansible.com/t/template-variable-and-host-file/8454/3 "2024-09-13T09:38:23Z")

</div>

thak you.  
I solved with hostvar.  
I put in my template.yml `variable_name: "{{ variable_name }}"`  
in host file :  
`ansible_host=x.y.z.k variable_name=xx`
