Can not copy file from local to VM created by packer

I want make VM qcow2 image by packer and install some app like docker and kubectl on by ansible. everything is OK and I can install some packages I need on VM like docker…

but I want ansible copy one bash script from my local to VM and run that script after copy.

but I get this error

qemu.template: TASK [Copy to server] **************************************************
    qemu.template: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
    qemu.template: fatal: []: FAILED! => {"changed": false, "msg": "Could not find or access '/root/' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}

Permission of file is OK, but I do not know why I get this error.

this is my task on playbook

- name : Copy to server
        src: /root/  
        dest: /home/ubuntu/repair mode=0777
        remote_src: yes
        owner: root
    - name: Run script
      command: sh /home/ubuntu/

Does /root/ exist on the remote server?

If you want to copy /root/ to the server then remove remote_src: yes.

Also you have a mismatch on the file name, you have home/ubuntu/repair and /home/ubuntu/ you should use one or the other.

1 Like

/root/ does not exit on remote server. is on my host Linux. host Linux is Ubuntu and has only root user.
remote host is Ubuntu too and has only Ubuntu user.
I want copy from my host to remote host.

Hi, as @chris mentioned, we believe remote_src should not be yes.
See the docs to know what remote_src is for: ansible.builtin.copy module – Copy files to remote locations — Ansible Community Documentation


I remove remote_src but I got that error again

Please always provide not only explaining your situation but also complete tasks, and logs.
Also provide output of the commands to ensure the source file exists on the desired path on the desired node.

1 Like