knowledge/technology/tools/Ansible/modules/ansible.builtin.fetch.md
2023-12-04 11:02:23 +01:00

39 lines
No EOL
1.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ansible.builtin.fetch
- Fetch files from remote nodes
- This module works like [ansible.builtin.copy](ansible.builtin.copy.md), 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 dest will be overwritten if they are different than the src.
## Parameter
| Parameter | Type | Default | Description |
| --------------------- | ----------------- | ------- | ---------------------------------------------------------------------------------------- |
| **dest** | string / required | - | A directory to save the file into. |
| **fail_on_missing** | boolean | true | When set to `true`, the task will fail if the remote file cannot be read for any reason. |
| **src** | string / required | - | The file on the remote system to fetch.  This must be a file, not a directory. |
| **validate_checksum** | boolean | true | Verify that the source and destination checksums match after the files are fetched. |
## Examples
```yaml
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile
ansible.builtin.fetch:
src: /tmp/somefile
dest: /tmp/fetched
- name: Specifying a path directly
ansible.builtin.fetch:
src: /tmp/somefile
dest: /tmp/prefix-{{ inventory_hostname }}
flat: yes
- name: Specifying a destination path
ansible.builtin.fetch:
src: /tmp/uniquefile
dest: /tmp/special/
flat: yes
- name: Storing in a path relative to the playbook
ansible.builtin.fetch:
src: /tmp/uniquefile
dest: special/prefix-{{ inventory_hostname }}
flat: yes
```