心心失意 发表于 2018-7-29 13:16:47

[ansible学习笔记]fetch模块

  摘自官方文档:

[*]  This module works like copy, but in reverse. It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname. Note that this module is written to transfer log files that might not be present, so a missing remote file won’t be an error unless fail_on_missing is set to ‘yes’.
  选项:
parameterrequireddefaultchoicescommentsdestyes  A directory to save the file into. For example, if the dest directory is /backup a src file named /etc/profile on host host.example.com, would be saved into /backup/host.example.com/etc/profile
fail_on_missingnono

[*]  yes
[*]  no
  When set to 'yes', the task will fail if the source file is missing.
flatno  Allows you to override the default behavior of appending hostname/path/to/file to the destination. If 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.
srcyes
  The file on the remote system to fetch. This must be a file, not a directory. Recursive fetching may be supported in a later>validate_checksum  (added in 1.4)
noyes

[*]  yes
[*]  no
  Verify that the source and destination checksums match after the files are fetched.
  aliases: validate_md5
  样例:
  # cat roles/common/tasks/main.yml
  ---
  - name: fetch
  fetch:
  src: /etc/hosts
  dest: /tmp/fetchdir
  # cat site.yml
  ---
  - hosts: app
  tasks:
  - name: mkdir -p /tmp/fetchdir
  command: mkdir -p /tmp/fetchdir
  roles:
  - common
  # ansible-playbook site.yml
  SSH password:
  PLAY *********************************************************************
  TASK *******************************************************************
  ok:
  ok:
  TASK **********************************************************
  changed:
  changed:
  TASK **************************************************
  changed:
  : Consider using file module with state=directory rather than running mkdir
  changed:
  PLAY RECAP *********************************************************************
  rhel56-192.168.209.133   : ok=3    changed=2    unreachable=0    failed=0
  rhel61-192.168.209.142   : ok=3    changed=2    unreachable=0    failed=0
  # ll /tmp/fetchdir/{rhel56-192.168.209.133,rhel61-192.168.209.142}/etc/
  /tmp/fetchdir/rhel56-192.168.209.133/etc/:
  total 4
  -rw-r--r-- 1 root root 187 Feb 16 18:31 hosts
  /tmp/fetchdir/rhel61-192.168.209.142/etc/:
  total 4
  -rw-r--r-- 1 root root 158 Feb 16 18:31 hosts
页: [1]
查看完整版本: [ansible学习笔记]fetch模块