Ansible - Get play name using the ansible_play_name variable

by
Jeremy Canfield |
Updated: June 05 2025
| Ansible articles
Let's say you have the following playbook. Notice in this example that there are two plays, First Play and Second Play.
---
- name: First Play
hosts: localhost
tasks:
- ansible.builtin.debug:
var: ansible_play_name
- name: Second Play
hosts: localhost
tasks:
- ansible.builtin.debug:
var: ansible_play_name
...
Running this playbook should return the following. Notice in this example that ansible_play_name contains each play name.
PLAY [First Play]
TASK [Gathering Facts]
ok: [localhost]
TASK [ansible.builtin.debug]
ok: [localhost] => {
"ansible_play_name": "First Play"
}
PLAY [Second Play]
TASK [Gathering Facts]
ok: [localhost]
TASK [ansible.builtin.debug]
ok: [localhost] => {
"ansible_play_name": "Second Play"
}
PLAY RECAP
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Did you find this article helpful?
If so, consider buying me a coffee over at