码迷,mamicode.com
首页 > 其他好文 > 详细

ansible files module: fetch & copy & template.....continuing

时间:2016-07-14 19:36:02      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:自动化运维   ansible   files模块

fetch模块与copy功能是一样的,都是不同机器之间文件传输,前者是从节点拉取文件到主控机(装有ansible的机器),后者是从主控机传输文件到节点。template模块能在复制文件中插入变量。

(官方文档)The copy module copies a file on the local box to remote locations. Use the fetch module to copy files from remote locations to the local box. If you need variable interpolation in copied files, use the template module.

常用参数:

src和dest即source和destination的简称,忽略。

fail_on_missing=yes,如果source file不存在,任务就会失败。

以下命令行举例说明:

1、#ansible hostname -m fetch -a "src=/tmp/srcfile dest=/tmp/destdir"

不管dest是不是以“/”结尾,目标文件在主控机上的路径都是:/tmp/destdir/hostname/tmp/srcfile


2、#ansible hostname -m fetch -a "src=/tmp/srcfile dest=/tmp/destdir/ flag=yes"

目标文件在主控机上的路径:/tmp/destdir/srcfile

以我自己运行操作以下几种都会报错

#ansible hostname -m fetch -a "src=/tmp/srcfile dest=/tmp/destdir flag=yes"

#ansible hostname -m fetch -a "src=/tmp/* dest=/tmp/destdir/ flag=yes"我还以为src /tmp目录下的文件都会拷贝到/tmp/destdir目录下


3、#ansible hostname -m fetch -a "src=/tmp/srcfile dest=/tmp/destdir/12345 flag=yes"

目标文件在主控机上的路径:/tmp/destdir/12345 其实对文件重命名(主控机上原本没有destdir目录)


4、#ansible hostname -m fetch -a "src=/tmp/srcfile dest=destdir/12345 flag=yes"

目标文件在主控机上的路径:/etc/ansible/destdir/12345(相对于ansible主路径)

本文出自 “11524698” 博客,请务必保留此出处http://11534698.blog.51cto.com/11524698/1826465

ansible files module: fetch & copy & template.....continuing

标签:自动化运维   ansible   files模块

原文地址:http://11534698.blog.51cto.com/11524698/1826465

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!