ansible 復制文件到本地 localhost


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM