Вы можете сохранить имена ваших задач в переменных, но я бы сказал, что это может go против читабельности самого YAML playbook.
Пример:
- hosts: localhost
gather_facts: no
vars:
debug_name: foo
tasks:
- name: "{{ debug_name }}"
debug:
msg: Hello world!
register: debug_register
- debug:
msg: "Task named `{{ debug_name }}` resulted in {{ debug_register }}"
Дает резюме:
PLAY [localhost] **************************************************************************************************
TASK [foo] ********************************************************************************************************
ok: [localhost] => {
"msg": "Hello world!"
}
TASK [debug] ******************************************************************************************************
ok: [localhost] => {
"msg": "Task named `foo` resulted in {'msg': 'Hello world!', 'failed': False, 'changed': False}"
}
PLAY RECAP ********************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Вы также можете получить доступ к play , но не к задаче, имя через ansible_play_name
:
- name: Play 01
hosts: localhost
gather_facts: no
vars:
debug_name: foo
tasks:
- name: This is not the play, it is the task name
debug:
msg: "{{ ansible_play_name }}"
Укажите резюме
PLAY [Play 01] ****************************************************************************************************
TASK [This is not the play, it is the task name] *********************************************************************
ok: [localhost] => {
"msg": "Play 01"
}
PLAY RECAP ********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0