# How to get the hostname into jinja file

**URL:** <https://forum.ansible.com/t/how-to-get-the-hostname-into-jinja-file/35408>\
**Category:** Ansible Project\
**Created:** [June 25, 2021, 10:03am UTC](https://forum.ansible.com/t/how-to-get-the-hostname-into-jinja-file/35408 "2021-06-25T10:03:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdulrazzaq\_shaik](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Abdulrazzaq\_shaik](https://forum.ansible.com/u/Abdulrazzaq_shaik)\
**Post date:** [June 25, 2021, 10:03am UTC](https://forum.ansible.com/t/how-to-get-the-hostname-into-jinja-file/35408/1 "2021-06-25T10:03:40Z")

</div>

Hi Folks,

Thank you for reading this.

My expectation is to get the hostname from the inventory file, please help how to get this.

Jinjafile :

teaserverurl: “http://{{tibcoteahost}}:8777/tea”

vars file :

tibco\_tea\_group: “{{ groups[‘tibco\_tea’] | default(ansible\_play\_hosts) | sort }}”  
tibcoteahost: \>  
“{% for server in tibco\_tea\_group -%}  
{{ hostvars.get(server).ansible\_all\_ipv4\_addresses }}  
{% endfor %}”

inventory file:

---

<div class="post-metadata">

**Author:** ![Avinash\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@Avinash\_Krishnan](https://forum.ansible.com/u/Avinash_Krishnan)\
**Post date:** [June 26, 2021, 6:20am UTC](https://forum.ansible.com/t/how-to-get-the-hostname-into-jinja-file/35408/2 "2021-06-26T06:20:34Z")

</div>

Hi,

Are you looking to set the url on each server during playbook execution ? You can use magic variable inventory\_hostname to dynamically get hostname during play execution.

**teaserverurl: “http://{{ inventory\_hostname }}:8777/tea”**
