# Is there a way to get current task name?

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524>\
**Category:** Ansible Project\
**Created:** [January 25, 2019, 10:35am UTC](https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524 "2019-01-25T10:35:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lionel\_Felicite](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@Lionel\_Felicite](https://forum.ansible.com/u/Lionel_Felicite)\
**Post date:** [January 25, 2019, 10:35am UTC](https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524/1 "2019-01-25T10:35:17Z")

</div>

Hi all,

Is there a way to get the current task name?

With this example plyabook, I got an undefined “name” variable

> * * *
> 
> - hosts: all
> 
> tasks:
> 
> - name: Dump all vars  
> debug:  
> msg: “echo task name is {{ name }}”

Error message is

> ansible-playbook -i inventory/local dumpall.yml
> 
> PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [localhost]
> 
> TASK [Dump all vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [localhost]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘name’ is undefined\n\nThe error appears to have been in ‘dumpall.yml’: line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Dump all vars\n ^ here\n”}  
> to retry, use: --limit @dumpall.retry
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> localhost : ok=1 changed=0 unreachable=0 failed=1

inventory/local:

> [local]  
> localhost ansible\_connection=local

My environement:

- debian 9
- ansible 2.7.5 in virtualenv

Thanks  
Lionel

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 1, 2019, 8:25pm UTC](https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524/2 "2019-02-01T20:25:19Z")

</div>

no, there is very little 'introspection' to the task itself.

---

<div class="post-metadata">

**Author:** ![Lionel\_Felicite](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@Lionel\_Felicite](https://forum.ansible.com/u/Lionel_Felicite)\
**Post date:** [February 4, 2019, 9:02am UTC](https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524/3 "2019-02-04T09:02:06Z")

</div>

OK.

Thanks, Brian.

Lionel

---

<div class="post-metadata">

**Author:** ![cyril.stoll1](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@cyril.stoll1](https://forum.ansible.com/u/cyril.stoll1)\
**Post date:** [February 4, 2019, 4:53pm UTC](https://forum.ansible.com/t/is-there-a-way-to-get-current-task-name/29524/4 "2019-02-04T16:53:43Z")

</div>

Hi Lionel

> Is there a way to get the current task name?

It is quite obvious but you might have missed it anyway. You do see the task name in the square brackets between “TASK” and “\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*” where it says [Dump all vars] which is the name part of your task…

> TASK [Dump all vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [localhost]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘name’ is undefined\n\nThe error appears to have been in ‘dumpall.yml’: line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Dump all vars\n ^ here\n”}  
> to retry, use: --limit @dumpall.retry

Otherwise you might need to specify what you want to achieve or where you need to access the task name. Maybe someone knows a way to accomplish what you want.

Regards,  
Cyril
