fetch
從遠端獲取文件,將這些文件按照樹型方式按主機名分類進行存儲。
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
dest - / required | 存儲目標的目錄。如果 dest 是 /backup , src 在host.exmaple.com 的位置是 /etc/profile , 那么最終的存儲路徑是/backup/host.example.com/etc/profile ,主機名的依據是 inventory name 。 |
|
fail_on_missing boolean | Choices:noyes | 如果設置成yes ,在讀取不到遠端文件時會報錯。 |
flat boolean | Choices:noyes | 是否改變默認的將 hostname/path/to/file 追加到 dest 目錄后。默認是no ,即不允許改變這種默認的的文件組織方式,為的是如果有多個主機,dest 為同一個文件會被覆蓋。如果是yes ,假如 dest 是 / 結尾,則文件保存在dest 目錄中;假如dest 是文件,則直接保存為dest 文件。 |
src - / required | 只能是文件,不能是目錄(2.9),后面可能會支持目錄。 | |
validate_checksum boolean | Choices:noyes | 獲取文件后是否比較文件是否一致。 |
Exmaple
- 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
slurp
從遠端獲取文件內容,並可以注冊為變量(base64格式)
Examples
- name: Find out what the remote machine's mounts are
slurp:
src: /proc/mounts
register: mounts
- debug:
msg: "{{ mounts['content'] | b64decode }}"
# From the commandline, find the pid of the remote machine's sshd
# $ ansible host -m slurp -a 'src=/var/run/sshd.pid'
# host | SUCCESS => {
# "changed": false,
# "content": "MjE3OQo=",
# "encoding": "base64",
# "source": "/var/run/sshd.pid"
# }
# $ echo MjE3OQo= | base64 -d
# 2179