# Can not copy file from local to VM created by packer

**URL:** <https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209>\
**Category:** Get Help\
**Created:** [April 30, 2024, 6:21am UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209 "2024-04-30T06:21:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mostafa\_Faridi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mostafa_faridi/32/3032_2.png) [@Mostafa\_Faridi](https://forum.ansible.com/u/Mostafa_Faridi)\
**Post date:** [April 30, 2024, 6:21am UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/1 "2024-04-30T06:21:19Z")

</div>

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

```auto
qemu.template: TASK [Copy repair.sh 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: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Could not find or access '/root/repair.sh' 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

```auto
- name : Copy repair.sh to server
      ansible.builtin.copy:
        src: /root/repair.sh  
        dest: /home/ubuntu/repair mode=0777
        remote_src: yes
        owner: root
    - name: Run script
      command: sh /home/ubuntu/repair.sh

```

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 30, 2024, 10:09pm UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/2 "2024-04-30T22:09:58Z")

</div>

Does `/root/repair.sh` exist on the remote server?

If you want to copy `/root/repair.sh` 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/repair.sh` you should use one or the other.

---

<div class="post-metadata">

**Author:** ![Mostafa\_Faridi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mostafa_faridi/32/3032_2.png) [@Mostafa\_Faridi](https://forum.ansible.com/u/Mostafa_Faridi)\
**Post date:** [May 1, 2024, 5:54am UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/3 "2024-05-01T05:54:14Z")

</div>

Thanks,  
/root/repair.sh does not exit on remote server.  
repair.sh 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 repair.sh from my host to remote host.

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [May 1, 2024, 12:08pm UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/4 "2024-05-01T12:08:30Z")

</div>

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](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html)

---

<div class="post-metadata">

**Author:** ![Mostafa\_Faridi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mostafa_faridi/32/3032_2.png) [@Mostafa\_Faridi](https://forum.ansible.com/u/Mostafa_Faridi)\
**Post date:** [May 5, 2024, 6:07am UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/5 "2024-05-05T06:07:54Z")

</div>

Thank,  
I remove remote\_src but I got that error again

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [May 5, 2024, 6:27am UTC](https://forum.ansible.com/t/can-not-copy-file-from-local-to-vm-created-by-packer/5209/6 "2024-05-05T06:27:46Z")

</div>

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.
