Ansible variables that tells you the location in the controller's file system

published May 08, 2017 10:40   by admin ( last modified Jun 30, 2017 12:44 )

Taken from here, where there is a list of many more variables in Ansible: lorin/ansible-quickref: Quick reference for Ansible variables

  Description
playbook_dir Directory that contains the playbook being executed
inventory_dir Directory that contains the inventory
inventory_file Host file or script path (?)

If you are using included playbooks, playbook_dir get really confused. It will report a path such as:

/home/use/playbook_dir/./sub_playbook_dir

You can truncate the path to before the dot, with a filter, like this:

"{{ playbook_dir | regex_replace('(/\\./.*)', '')  }}