
name: Copying the Directory's contents (sub directories/files) This is a playbook form of the same ad hoc command - name: Ansible Copy Directory Example Local to Remote Refer the following screenshot of executing this ansible ad hoc command and the results on the remote dest directory. You need to notice that there is a / at the end of src path ~/Downloads/logos/ If there is no slash at the end that is Type#2 This is an ansible AD HOC command to copy a directory’s content to the remote server ansible remoteserver -m copy -a "src=~/Downloads/logos/ dest=/var/www/html/ owner=apache group=apache mode=0644 " -i ansible_hosts -b the content can be a directory(subdirectory) or a file. In this Type, Only the Directory’s content would be copied. Type#1 Copy directory’s content with ansible in a recursive manner Hope the following image with tree command output helps to understand this point. Ansible would take care of creating the new directory at the remote server In Type#2, Ansible copies the directory to the remote server along with the content of the directory.

In Type#1 only the contents of the src directory would be copied to the destination directory. While the preceding key points look similar, they are not.

#Ssh copy directory how to#
How to copy directories with Ansible – Local to Remote Here is the execution output of these commands in a short clip ansible remoteserver1 -m copy -a "src=~/Downloads/index.html dest=/var/www/html owner=apache group=apache mode=0644" This can be executed in a single line as an ad hoc command as well. 0644 would be set as permission on the file rw- r- r.

