I am trying to copy the content of dist directory to nginx directory.
- name: copy html file
copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/
But when I execute the playbook it throws an error:
TASK [NGINX : copy html file] **************************************************
fatal: [172.16.8.200]: FAILED! => {"changed": false, "failed": true, "msg": "attempted to take checksum of directory:/home/vagrant/dist/"}
How can I copy a directory that has another directory and a file inside?
I got involved whole a day, too! and finally found the solution in
shell
command instead of copy: or command: as below:strictly notice to: 1. src_path and des_path end by
/
symbol 2. in shell command src_path ends by.
which shows all content of directory 3. I used my remote-server-name both in hosts: and execute shell section of jenkins, instead ofremote_src:
specifier in playbook.I guess it is a good advice to run below command in Execute Shell section in jenkins:
Ansible Copy module by default copies files/dirs from control machine to remote machine. If you want to copy files/dirs in remote machine and if you have Ansible 2.0, set
remote_src
toyes
The simplest solution I've found to copy the contents of a folder without copying the folder itself is to use the following:
This resolves @surfer190's follow-up question:
*
is a shell glob, in that it relies on your shell to enumerate all the files within the folder before runningcp
, while the.
directly instructscp
to get the directory contents (see https://askubuntu.com/questions/86822/how-can-i-copy-the-contents-of-a-folder-to-another-folder-in-a-different-directo)You could use the synchronize module. The example from the documentation:
This has the added benefit that it will be more efficient for large/many files.
This I found an ideal solution for copying file from Ansible server to remote.
copying yaml file
I found a workaround for recursive copying from remote to remote :