dirname

The inverse of basename is dirname. Instead of returning the final part of a path, dirname will return everything, except the final part. Let's change our previous play to use dirname and rerun it:

We now have just the path of our variable, which could be extremely useful elsewhere in our playbook.

Get Mastering Ansible - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.