Ansible - playbook_dir magic variable

Let's say you've a playbook named foo.yml that exists in the /usr/local directory, like this.



The playbook_dir variable will contain the directory that contains the playbook. Here is how you would print the playbook_dir variable.

- name: "output the 'playbook_dir' variable"
    msg: "{{ playbook_dir }}"


Running this playbook should produce the following.

TASK [output the 'playbook_dir' variable] 
ok: [] => {
    "msg": "/usr/local"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

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


Web design by yours truely - me, myself, and I   |   |