Bootstrap FreeKB - Ansible - Get play name using the ansible_play_name variable
Ansible - Get play name using the ansible_play_name variable

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter a4da6b in the box below so that we can be sure you are a human.