How to copy files from remote to host ansible?

旧时模样 提交于 2020-01-04 02:00:26

问题


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.


回答1:


From 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

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

If you had used -v option, it would have printed the location of the fetched file. I ran the playbook from /tmp directory.

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


来源:https://stackoverflow.com/questions/41193929/how-to-copy-files-from-remote-to-host-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!