How can i use Host Variables in Task name

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.

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 }}"

Try this:

   vars:
      AIR: "{{ AIRID }}"
      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

Should be in this format : -

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

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

Hello,

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