# How can i use Host Variables in Task name

**URL:** <https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998>\
**Category:** Ansible Project\
**Tags:** awx\
**Created:** [October 9, 2020, 3:33pm UTC](https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998 "2020-10-09T15:33:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Ankit2](https://forum.ansible.com/u/Ankit2)\
**Post date:** [October 9, 2020, 3:33pm UTC](https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998/1 "2020-10-09T15:33:51Z")

</div>

Hello Everyone,

I am trying to use the host variables set for each host of inventory in the task name but for some reason, it doesn’t work.

I have got a dynamic inventory (hosts imported in AWX using it) and all the hosts have got their own variables updated based on the information available from source. There are 2 variables in the task name which i want to use in such a way that they are updated every time a task runs for each host of inventory. Ex variable for one of the host:

**AID: 1234**  
**Environment: Staging**

What i have been trying:

**- hosts: all**  
**vars:**  
**AIR: “{{ hostvars.AIRID }}”**  
**ENVI: “{{ hostvars.Environment }}”**

**- name: “Event Logs for AIRID={{ AIR }} ENVIRONMENT={{ ENVI }}”**  
**command: some command here**

What i get in the result for task name is:

**TASK [Event Logs for AIRID={{ AIR }} ENVIRONMENT={{ ENVI }}]**

I have even tried set\_fact task before this task but that too doesn’t work. Can anyone suggest how can i get the host variables in task name?

**_PS: Please ignore the indentation, this maybe because of formatting change in the post._**

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 9, 2020, 3:54pm UTC](https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998/2 "2020-10-09T15:54:37Z")

</div>

> Hello Everyone,
> 
> I am trying to use the host variables set for each host of inventory in the task name but for some reason, it doesn't work.
> 
> I have got a dynamic inventory (hosts imported in AWX using it) and all the hosts have got their own variables updated based on the information available from source. There are 2 variables in the task name which i want to use in such a way that they are updated every time a task runs for each host of inventory. Ex variable for one of the host:
> 
> AID: 1234  
> Environment: Staging
> 
> What i have been trying:
> 
> - hosts: all  
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AIR: "{{ hostvars.AIRID }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENVI: "{{ hostvars.Environment }}"

Try this:

&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AIR: "{{ AIRID }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENVI: "{{ Environment }}"

> PS: Please ignore the indentation, this maybe because of formatting change in the post.

Use plain text instead - no formatting issues there.

DIck

---

<div class="post-metadata">

**Author:** ![Tej-Singh-Rana](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@Tej-Singh-Rana](https://forum.ansible.com/u/Tej-Singh-Rana)\
**Post date:** [October 9, 2020, 4:09pm UTC](https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998/3 "2020-10-09T16:09:40Z")

</div>

Should be in this format : -

vars:  
user: “{{ hostvars[‘host-name’][‘name’] }}”  
tasks:

- name: 'Name is {{ user }} ’

---

<div class="post-metadata">

**Author:** ![Ankit2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Ankit2](https://forum.ansible.com/u/Ankit2)\
**Post date:** [October 16, 2020, 3:28pm UTC](https://forum.ansible.com/t/how-can-i-use-host-variables-in-task-name/33998/4 "2020-10-16T15:28:39Z")

</div>

Hello,

Thanks for your response. Sadly, it didn’t work.
