ansible.builtin.path_join filter – Join one or more path components

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 path_join 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.

New in ansible-base 2.10

Synopsis

  • Returns a path obtained by joining one or more path components.

Input

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

Parameter

Comments

Input

list / elements=string / required

A path, or a list of paths.

Examples

# If path == 'foo/bar' and file == 'baz.txt', the result is '/etc/foo/bar/subdir/baz.txt'
{{ ('/etc', path, 'subdir', file) | path_join }}

# equivalent to '/etc/subdir/{{filename}}'
wheremyfile: "{{ ['/etc', 'subdir', filename] | path_join }}"

# trustme => '/etc/apt/trusted.d/mykey.gpgp'
trustme: "{{ ['/etc', 'apt', 'trusted.d', 'mykey.gpg'] | path_join }}"

Return Value

Key

Description

Return value

string

The concatenated path.

Returned: success

Authors

  • Anthony Bourguignon (@Toniob)

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.