Is there a way to get current task name?

30 views
Skip to first unread message

Lionel Félicité

unread,
Jan 25, 2019, 5:35:17 AM1/25/19
to Ansible Project
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
 

Brian Coca

unread,
Feb 1, 2019, 3:25:42 PM2/1/19
to Ansible Project
no, there is very little 'introspection' to the task itself.



--
----------
Brian Coca

Lionel Félicité

unread,
Feb 4, 2019, 4:02:51 AM2/4/19
to ansible...@googlegroups.com
OK.

Thanks, Brian.

Lionel

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7d7AQz4V9KKeN7R2iah2kzdqJDqS2o-pEzoYpb7UFwYeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Lionel FÉLICITÉ - http://www.clever-age.com/
Tél : +33 1 53 34 66 10

Clever Forge - Digital Architecture
Clever Garden - Digital Landscape
Clever Presence - Digital Running

cyril...@zi.uzh.ch

unread,
Feb 4, 2019, 11:53:43 AM2/4/19
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages