ansible.builtin.basename filter – get a path’s base 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
basename
even without specifying the collections:
keyword.
However, we recommend you use the FQCN 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 last name component of a path, what is left in the string that is not ‘dirname’.
Input
This describes the input of the filter, the value before | ansible.builtin.basename
.
Parameter |
Comments |
---|---|
A path. |
See Also
See also
- ansible.builtin.dirname filter plugin
The official documentation on the ansible.builtin.dirname filter plugin.
Examples
# To get the last name of a file path, like 'foo.txt' out of '/etc/asdf/foo.txt'
{{ mypath | basename }}
Return Value
Key |
Description |
---|---|
The base name from the path provided. Returned: success |