ansible.builtin.fetch (v2.8.15) — module

Fetch files from remote nodes

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

Authors: Ansible Core Team, Michael DeHaan

stableinterface | supported by core

Install Ansible via pip

Install with pip install ansible==2.8.15

Description

This module works like M(copy), but in reverse.

It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.

This module is also supported for Windows targets.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile
  fetch:
    src: /tmp/somefile
    dest: /tmp/fetched
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Specifying a path directly
  fetch:
    src: /tmp/somefile
    dest: /tmp/prefix-{{ inventory_hostname }}
    flat: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Specifying a destination path
  fetch:
    src: /tmp/uniquefile
    dest: /tmp/special/
    flat: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Storing in a path relative to the playbook
  fetch:
    src: /tmp/uniquefile
    dest: special/prefix-{{ inventory_hostname }}
    flat: yes

Inputs

    
src:
    description:
    - The file on the remote system to fetch.
    - This I(must) be a file, not a directory.
    - Recursive fetching may be supported in a later release.
    required: true

dest:
    description:
    - A directory to save the file into.
    - For example, if the I(dest) directory is C(/backup) a I(src) file named C(/etc/profile)
      on host C(host.example.com), would be saved into C(/backup/host.example.com/etc/profile).
      The host name is based on the inventory name.
    required: true

flat:
    default: false
    description:
    - Allows you to override the default behavior of appending hostname/path/to/file to
      the destination.
    - If C(dest) ends with '/', it will use the basename of the source file, similar to
      the copy module.
    - Obviously this is only handy if the filenames are unique.
    type: bool
    version_added: '1.2'
    version_added_collection: ansible.builtin

fail_on_missing:
    default: true
    description:
    - When set to C(yes), the task will fail if the remote file cannot be read for any
      reason.
    - Prior to Ansible 2.5, setting this would only fail if the source file was missing.
    - The default was changed to C(yes) in Ansible 2.5.
    type: bool
    version_added: '1.1'
    version_added_collection: ansible.builtin

validate_checksum:
    default: true
    description:
    - Verify that the source and destination checksums match after the files are fetched.
    type: bool
    version_added: '1.4'
    version_added_collection: ansible.builtin

See also