Current ansible-playbook Path — playbook_dir Magic Variable — Ansible Tip and Tricks
How to display the current execution Ansible Playbook file system path using the “playbook_dir” Magic Variables for debugging and simplifying your automation journey.
--
How to display the Current ansible-playbook Path?
I’m going to show you how to Use the “playbook_dir” Ansible Magic Variable in Ansible Playbook with a live demo and some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible Magic Variables
- playbook_dir
The path to the directory of the playbook that was passed to the ansible-playbook command line
How to Ansible Magic Variables in Ansible Playbook.
The good news is that Ansible provides some internal variables that come out of the box with some information such as running the Ansible version, inventory details, or execution options.
The full list is available on the official Ansible website https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
demo
Use “playbook_dir” Ansible Magic Variable in Ansible Playbook
How to display the Current ansible-playbook Path? I’m going to show you how to user the “playbook_dir” Ansible Magic Variable in Ansible Playbook.
Let’s see in action some of the most common Ansible Magic Variables in an Ansible Playbook.
code
---
- name: playbook directory demo
hosts: all
gather_facts: false
tasks:
- name: print current playbook directory
ansible.builtin.debug:
var: playbook_dir
execution
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory file_management/file_playbookdir.ymlPLAY [playbook directory demo]…