ansible.builtin.relpath filter – Make a path relative

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 relpath 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

  • Converts the given path to a relative path from the start, or relative to the directory given in start.

Input

This describes the input of the filter, the value before | ansible.builtin.relpath.

Parameter

Comments

Input

string / required

A path.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.relpath(positional1, positional2, ...)

Parameter

Comments

start

string

The directory the path should be relative to. If not supplied the current working directory will be used.

Examples

# foobar => ../test/me.txt
testing: "{{ '/tmp/test/me.txt' | relpath('/tmp/other/') }}"
otherrelpath: "{{ mypath | relpath(mydir) }}"

Return Value

Key

Description

Return value

string

The relative path.

Returned: success

Authors

  • Jakub Jirutka (@jirutka)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.