ansible.builtin.file (v2.16.5) — lookup

read file contents

| "added in version" 0.9 of ansible.builtin"

Authors: Daniel Hokka Zakrisson (!UNKNOWN) <daniel@hozac.com>

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

This lookup returns the contents from a file on the Ansible controller's file system.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.debug:
    msg: "the value of foo.txt is {{ lookup('ansible.builtin.file', '/etc/foo.txt') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: display multiple file contents
  ansible.builtin.debug: var=item
  with_file:
    - "/path/to/foo.txt"
    - "bar.txt"  # will be looked in files/ dir relative to play or in role
    - "/path/to/biz.txt"

Inputs

    
_terms:
    description: path(s) of files to read
    required: true

lstrip:
    default: false
    description: whether or not to remove whitespace from the beginning of the looked-up
      file
    required: false
    type: bool

rstrip:
    default: true
    description: whether or not to remove whitespace from the ending of the looked-up
      file
    required: false
    type: bool

Outputs

_raw:
  description:
  - content of file(s)
  elements: str
  type: list

See also