asfenpalace.blogg.se

Ssh copy directory
Ssh copy directory














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.

ssh copy 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

  • Type2: Copy the Source Directory and its contents.
  • Type1: Copy the Source Directory’s contents (but not the directory).
  • But there are two variations while copying the directory You can copy directories with Ansible copy module.

    #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.

  • mode: setting the permission of the file after copying.
  • group: Group of the file at the destination server once copied.
  • owner: Owner of the file at the destination server once copied.
  • dest: destination path on the remote server/host where the file should be copied to.
  • ssh copy directory

  • src: source file path on the local machine where the playbook or ad-hoc command is invoked ( can set ansible to look for the file in remote server using remote_src as well ).
  • copy: module name we are going to use in this task.
  • become: this is to tell ansible to execute the corresponding task as a sudo user root unless specified any other user with become_user.
  • tasks: all the tasks (plays) would be defined under this.
  • hosts: A target host group should be already defined in the ansible inventory aka hosts file.
  • name: Ansible Copy Example Local to Remote














    Ssh copy directory