Skip to content

basename

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 last name component of a path, what is left in the string that is not 'dirname'.

Parameters

Parameter Defaults / Choices Comments
_input
path
required
A path.

Notes

Note

  • The result of this filter is different from the Unix basename program; where basename for C(/foo/bar/) returns C(bar), the basename filter returns an empty string (C('')).

Examples

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

Return Values

Key Data Type Description Returned
_value str The base name from the path provided.

Authors

  • Ansible Core Team