如何将文件从远程复制到主机ansible?
How to copy files from remote to host ansible?
我正在尝试将文件从远程主机复制到我所在的本地服务器 运行 Ansible 剧本。虽然任务总是成功执行,但文件永远不会复制到本地服务器。这是代码:
- file:
path: vm_info.config
mode: 0777
- fetch:
src: vm_info.config
dest: .
#flat: yes
fail_on_missing: yes
我也尝试了复制模块,但其中 none 正在为我提供结果。
来自fetch - Fetches a file from remote nodes
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
如果您使用了 -v 选项,它会打印出获取文件的位置。我 运行 /tmp 目录中的剧本。
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 剧本。虽然任务总是成功执行,但文件永远不会复制到本地服务器。这是代码:
- file:
path: vm_info.config
mode: 0777
- fetch:
src: vm_info.config
dest: .
#flat: yes
fail_on_missing: yes
我也尝试了复制模块,但其中 none 正在为我提供结果。
来自fetch - Fetches a file from remote nodes
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
如果您使用了 -v 选项,它会打印出获取文件的位置。我 运行 /tmp 目录中的剧本。
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