Template variable and host file

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

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

Have a look at my updated examples Repo: ansible-examples/lamp_simple at master · RayJin2000/ansible-examples · GitHub

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