# Variable interpolation in task name

**URL:** <https://forum.ansible.com/t/variable-interpolation-in-task-name/15192>\
**Category:** Ansible Project\
**Created:** [May 7, 2014, 8:28pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192 "2014-05-07T20:28:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 7, 2014, 8:28pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/1 "2014-05-07T20:28:22Z")

</div>

Hi,

I have a role that updates DNS records. It contains a number of tasks such as:

- name: Create A record  
route53: command=create [zone=example.com](http://zone=example.com) record={{ domain }} type=A value={{ ip }}

Other roles (that represent server profiles) depend on this role like this:

- role: dns  
domain: “{{ website\_domain }}”  
ip: “{{ ansible\_default\_ipv4.address }}”

The problem is that the role execution does not give a lot of information because the name of the task is the same every time. Of course I could use a debug task, but I thought I would put the domain in the task name, like this:

- name: Create A record for domain {{ domain }}

Unfortunately, the variable interpolation does not work well, it seems to go only one “level” deep. This is the output:

TASK: [dns | Create A record for {{website\_domain}}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[web1.example.com](http://web1.example.com)]

My question: is this expected behavior? Otherwise I will try and isolate the problem and create an issue.

Regards,  
Joost

---

<div class="post-metadata">

**Author:** ![Slava\_Semushin](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Slava\_Semushin](https://forum.ansible.com/u/Slava_Semushin)\
**Post date:** [May 8, 2014, 6:21am UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/2 "2014-05-08T06:21:52Z")

</div>

Hi,

[...]

> - name: Create A record for domain {{ domain }}
> 
> Unfortunately, the variable interpolation does not work well, it seems to go  
> only one "level" deep. This is the output:
> 
> TASK: [dns | Create A record for {{website\_domain}}]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [web1.example.com]

Have you tried with

- name: Create A record {{domain}}  
&nbsp;&nbsp;route53: command=create zone=example.com record={{ domain }} type=A  
value={{ ip }}

?

Because based on output above you used website\_domain variable which  
isn't available inside role.

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 8, 2014, 9:43pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/3 "2014-05-08T21:43:26Z")

</div>

I guess I was not clear. The variable website\_domain does exist, I was  
including only what I thought was the interesting bits. Ansible would  
have complained, by the way, if the variable had not existed.

The attached archive contains an isolated example. Run with  
"ansible-playbook test.yml -i hosts". Notice how the debug tasks print  
the contents of the variables foo and bar, while the task names both  
contain "{{ foo }}".

Regards,  
Joost

> **(attachments)**
>
> [ansible-namevar.zip](https://forum.ansible.com/uploads/short-url/oPam38HOZO5gOMlAqAsJqWv807q.zip) (1.47 KB)

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 9, 2014, 4:00pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/4 "2014-05-09T16:00:23Z")

</div>

You mean output like this during a play:

.......  
TASK: [base-mongodb | install mongodb RPMs v {{mongo\_version}}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [mongo1] =\>  
(item=mongodb-org-2.6.0,mongodb-org-server-2.6.0,mongodb-org-shell-2.6.0)  
.......

?

Personally I quite like the behaviour, I see it as useful to know what var  
is controlling that part of a playbook run - though I know colleagues who  
took the opposite view.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 9, 2014, 6:04pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/5 "2014-05-09T18:04:29Z")

</div>

you can interpolate variables, just not from every scope, only ones that maintain value across hosts (extra, vars, vars\_files, vars\_prompts, etc) but not inventory vars.​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 9, 2014, 7:11pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/6 "2014-05-09T19:11:04Z")

</div>

What Brian said. This is not a bug.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 9, 2014, 7:12pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/7 "2014-05-09T19:12:00Z")

</div>

To explaloate (this has been answered several times before), imagine you are managing 500 hosts and an the inventory variable is different on each one? There’s no way to show a good task header in that case.

The best course of action is to name each task and don’t have variables in the task name, so it prints out a nice description.

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 10, 2014, 8:04pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/8 "2014-05-10T20:04:16Z")

</div>

> To explaloate (this has been answered several times before), imagine you are  
> managing 500 hosts and an the inventory variable is different on each one?  
> There's no way to show a good task header in that case.

Of course, that's it. There is no single value.

> The best course of action is to name each task and don't have variables in  
> the task name, so it prints out a nice description.

Well, that was my original problem. I have a generic role that creates  
DNS entries, that is depended upon by various other roles, in order  
to, well, create DNS entries. So there is not really a nice  
description to print out.

It has tasks like:

- name: Create A record for {{ domain }}  
&nbsp;&nbsp;route53: command=create zone={{ dns\_zone }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record={{ domain }} type=A ttl={{ ttl }} value={{  
ansible\_default\_ipv4.address }}

I was trying to get Ansible to print out the domains that are created  
without using the debug task, but I guess I will use debug after all.

By the way, I did search the list for variation on "name variable  
interpolation" but did not find anything. Thanks for explaining yet  
again!

Regards,  
Joost

---

<div class="post-metadata">

**Author:** ![Strahinja\_Kustudic2](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Strahinja\_Kustudic2](https://forum.ansible.com/u/Strahinja_Kustudic2)\
**Post date:** [May 11, 2014, 10:26am UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/9 "2014-05-11T10:26:11Z")

</div>

But, this should be possible to implement into Ansible? I would also like to use any variable which works in a task, to work in the task name. If you don’t have anything against this, I would like to create an issue on github, maybe someone takes it and implements it.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 11, 2014, 1:04pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/10 "2014-05-11T13:04:14Z")

</div>

The problem with “any variable” is that hosts share the task name, that is the main reason inventory variables don’t work

Brian Coca

---

<div class="post-metadata">

**Author:** ![Strahinja\_Kustudic2](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Strahinja\_Kustudic2](https://forum.ansible.com/u/Strahinja_Kustudic2)\
**Post date:** [May 11, 2014, 4:38pm UTC](https://forum.ansible.com/t/variable-interpolation-in-task-name/15192/11 "2014-05-11T16:38:39Z")

</div>

I see what you are saying. Since the tasks run in parallel for multiple servers and if servers have different values for the same variable in the inventory, or host\_vars, Ansible wouldn’t know how to name that task. Makes sense.
