Skip to content

dirname

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version historical.

Synopsis

  • Returns the 'head' component of a path, basically everything that is not the 'basename'.

Parameters

Parameter Defaults / Choices Comments
_input
path
required
A path.

Notes

Note

  • The result of this filter is different from the Unix dirname program; where dirname for C(/foo/bar/) returns C(/foo), the dirname filter returns the full path (C(/foo/bar/)).

Examples

# To get the dir name of a file path, like '/etc/asdf' out of '/etc/asdf/foo.txt'.
{{ mypath | dirname }}

Return Values

Key Data Type Description Returned
_value path The directory portion of the original path.

Authors

  • Ansible Core Team