[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’.

选项:

parameterrequireddefaultchoicescomments
dest
yes

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_missing
nono
  • yes

  • no

When set to 'yes', the task will fail if the source file is missing.

flat
no

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.

src
yes

The file on the remote system to fetch. This must be a file, not a directory. Recursive fetching may be supported in a later release.

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

样例:

[root@reedoracle reed]# cat roles/common/tasks/main.yml

---

- name: fetch

fetch:

src: /etc/hosts

dest: /tmp/fetchdir

[root@reedoracle reed]# cat site.yml

---

- hosts: app

tasks:

- name: mkdir -p /tmp/fetchdir

command: mkdir -p /tmp/fetchdir

roles:

- common

[root@reedoracle reed]# ansible-playbook site.yml

SSH password:

PLAY [app] *********************************************************************

TASK [setup] *******************************************************************

ok: [rhel56-192.168.209.133]

ok: [rhel61-192.168.209.142]

TASK [common : fetch] **********************************************************

changed: [rhel56-192.168.209.133]

changed: [rhel61-192.168.209.142]

TASK [mkdir -p /tmp/fetchdir] **************************************************

changed: [rhel56-192.168.209.133]

[WARNING]: Consider using file module with state=directory rather than running mkdir

changed: [rhel61-192.168.209.142]

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

[root@reedoracle reed]# 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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值