如何将文件从远程复制到主机ansible? [英] How to copy files from remote to host ansible?

查看:490
本文介绍了如何将文件从远程复制到主机ansible?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从远程主机复制到运行Ansible剧本的本地服务器.尽管任务总是成功执行,但是文件永远不会复制到本地服务器.这是代码:

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.

推荐答案

提取-提取文件从远程节点

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",目标": "/tmp/192.168.1.3/vm_info.config"、md5sum": "d41d8cd98f00b204e9800998ecf8427e","remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709","remote_md5sum":空}

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆