Skip to content

path_join

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

Synopsis

  • Returns a path obtained by joining one or more path components.
  • If a path component is an absolute path, then all previous components are ignored and joining continues from the absolute path. See examples for details.

Parameters

Parameter Defaults / Choices Comments
_input
list / elements=str
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.gpg'
trustme: "{{ ['/etc', 'apt', 'trusted.d', 'mykey.gpg'] | path_join }}"

# If one of the paths is absolute, then path_join ignores all previous path components
# If backup_dir == '/tmp' and backup_file == '/sample/baz.txt', the result is '/sample/baz.txt'
# backup_path => "/sample/baz.txt"
backup_path: "{{ ('/etc', backup_dir, backup_file) | path_join }}"

Return Values

Key Data Type Description Returned
_value str The concatenated path.

Authors

  • Anthony Bourguignon (@toniob)