ansible / ansible.builtin / v2.9.0 / module / fetch Fetch files from remote nodes | "added in version" 0.2 of ansible.builtin" Authors: Ansible Core Team, Michael DeHaan stableinterface | supported by coreansible.builtin.fetch (v2.9.0) — module
pip
Install with pip install ansible==2.9.0
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.
Files that already exist at I(dest) will be overwritten if they are different than the I(src).
This module is also supported for Windows targets.
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile fetch: src: /tmp/somefile dest: /tmp/fetched
- name: Specifying a path directly fetch: src: /tmp/somefile dest: /tmp/prefix-{{ inventory_hostname }} flat: yes
- name: Specifying a destination path fetch: src: /tmp/uniquefile dest: /tmp/special/ flat: yes
- name: Storing in a path relative to the playbook fetch: src: /tmp/uniquefile dest: special/prefix-{{ inventory_hostname }} flat: yes
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. - This can be useful if working with a single host, or if retrieving files that are uniquely named per host. - If using multiple hosts with the same filename, the file will be overwritten for each host. 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