How to copy a folder between two virtual machines?

Hi, I have vritual machine with Ansible. Now i want copy data from directory certyfikaty on svrhost to directory /svr/vaultwarden/cert folder on svrdocker. I don’t know what’s wrong, but below code dosen;t work

- name: Synchronizacja certyfikatów
  hosts: svrdocker
  become: yes
  tasks:
    - name: Kopiowanie plików z svrhost do svrdocker
      copy:
        src: /certyfikaty/czarnysad.ddns.net/
        dest: /svr/vaultwarden/cert
        remote_src: yes
        force: yes
      delegate_to: svrhost

Here is my inwentory file:

[servers]
svrhost ansible_host=10.0.0.12 ansible_user=Jan ansible_ssh_private_key_file=/root/.ssh/id_rsa
svrdocker ansible_host=10.0.0.16 ansible_user=Jan  ansible_ssh_private_key_file=/root/.ssh/id_rsa

result:


The path /svr/vaultwarden/cert is existing on svrdocker. I think that he try use acccess to path /svr/vaultwarden/cert on svrhost.
Kidn regards
Lukasz

Your current playbook is saying "copy /certyfikaty/czarnysad.ddns.net/ from svrhost to /svr/vaultwarden/cert on svrhost

Assuming you do not want to run ansible from svrhost, you could do one of

  1. use shell and delegate_to: svrhost to sftp the file over
  2. create some network mount on svrhost, then do copy like you have above, where the dest would be your network mounted path
  3. use slurp or fetch to pull the file from svrhost to the ansible host, then use copy without delegate_to and remote_src to copy the file to svrdocker

Hi, then ansible is running on other virutal machines. I think below pic explains it:

Ok, I understand that I can’t directly upload files from svrhost to svrdocker, I have to first upload them from svrhost to the virtual machine with ansible?

Yea, that is what the slurp or fetch modules will do

Ok, thx for your help :slight_smile:

while synchronize (see 2nd and other examples) can do this, it can be tricky and it only works if the machines can ssh to each other, otherwise i recommend to just do shell: scp -3 .. + delegate_to: localhost, which avoids copying the files to the controller, they are just streamed through.