ansible.builtin.file test – does the path resolve to an existing file

Note

This test plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name file 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 test plugin name.

Synopsis

  • Check if the provided path maps to an existing file on the controller’s filesystem (localhost)

Aliases: is_file

Input

This describes the input of the test, the value before is ansible.builtin.file or is not ansible.builtin.file.

Parameter

Comments

Input

path

A path.

Examples

vars:
  my_etc_hosts_is_a_file: "{{ '/etc/hosts' is file }}"
  list_of_files: "{{ list_of_paths | select('file') }}"

Return Value

Key

Description

Return value

boolean

Returns True if the path corresponds to an existing file on the filesystem on the controller, False if otherwise.

Returned: success

Authors

  • Ansible Core

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.