如何将文件从远程复制到主机 ansible? [英] How to copy files from remote to host ansible?
问题描述
我正在尝试将文件从远程主机复制到我运行 Ansible playbook 的本地服务器.虽然任务总是成功执行,但文件永远不会复制到本地服务器.代码如下:
I am trying to copy files from a remote host to my local server where I am running Ansible playbook. Though the task always executes successfully but the file is never copied to local server. Here is the code:
- file:
path: vm_info.config
mode: 0777
- fetch:
src: vm_info.config
dest: .
#flat: yes
fail_on_missing: yes
我也尝试过复制模块,但没有一个让我得到结果.
I tried copy module as well but none of them is getting me the result.
推荐答案
From fetch - 获取文件来自远程节点
dest - 保存文件的目录.例如,如果目标目录是/backup 主机上名为/etc/profile 的 src 文件host.example.com,将被保存到/backup/host.example.com/etc/profile
dest - 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
所以查看./remote-host/vm_info.config
.例如,您的远程主机是 192.168.1.3,提取的文件将是:./192.168.1.3/vm_info.config
So look in ./remote-host/vm_info.config
. For example, your remote host is 192.168.1.3, the fetched file will be: ./192.168.1.3/vm_info.config
如果您使用了 -v 选项,它将打印所获取文件的位置.我从/tmp 目录运行剧本.
If you had used -v option, it would have printed the location of the fetched file. I ran the playbook from /tmp directory.
任务 [获取]*********************************************************************** 已更改:[192.168.1.99] => {已更改":true,校验和":"da39a3ee5e6b4b0d3255bfef95601890afd80709", "dest":"/tmp/192.168.1.3/vm_info.config", "md5sum":"d41d8cd98f00b204e9800998ecf8427e", "remote_checksum":"da39a3ee5e6b4b0d3255bfef95601890afd80709", "remote_md5sum": null}
TASK [fetch] ******************************************************************* changed: [192.168.1.99] => {"changed": true, "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "dest": "/tmp/192.168.1.3/vm_info.config", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "remote_md5sum": null}
root@ip-192-168-1-99:~$ ls -l /tmp/192.168.1.3/vm_info.config
-rwxrwxr-x 1 root root 0 Dec 16 23:58 /tmp/192.168.1.3/vm_info.config
这篇关于如何将文件从远程复制到主机 ansible?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!