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

- 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

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.

1 Like

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.

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

2 Likes

Thank,
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