ansible.builtin.dirname filter – get a path’s directory name
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
dirname
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.dirname
for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
Synopsis
Returns the ‘head’ component of a path, basically everything that is not the ‘basename’.
Input
This describes the input of the filter, the value before | ansible.builtin.dirname
.
Parameter |
Comments |
---|---|
A path. |
Notes
Note
The result of this filter is different from the Unix dirname program; where dirname for
/foo/bar/
returns/foo
, the dirname filter returns the full path (/foo/bar/
).
See Also
See also
- ansible.builtin.basename filter plugin
get a path’s base name.
Examples
# To get the dir name of a file path, like '/etc/asdf' out of '/etc/asdf/foo.txt'.
{{ mypath | dirname }}
Return Value
Key |
Description |
---|---|
The directory portion of the original path. Returned: success |