dsollen
dsollen

Reputation: 6459

Ansible can't copy files on remote server, but the command runs correctly if run from command line

I'm trying to move everything under /opt/* to a new location on the remote server. I've tried this using command to run rsync directly, as well as using both the copy and the sychronize ansible module. In all cases I get the same error message saying:

 "msg": "rsync: link_stat \"/opt/*\" failed: No such file or directory

If I run the command listed in the "cmd" part of the ansible error message directly on my remote server it works without error. I'm not sure why ansible is failing.

Here is the current attempt using sychronize:

- name: move /opt to new partition
  become: true
  synchronize:
    src: /opt/*
    dest: /mnt/opt/*
  delegate_to: "{{ inventory_hostname }}"

Upvotes: 0

Views: 1227

Answers (1)

ikora
ikora

Reputation: 972

You should skip the wildcards that is a common mistake:

UPDATE Thanks to the user: @ Zeitounator, I managed to do it with synchronize. The advantage of using synchronize instead of copy module is performance, it's much faster if you have a lot of files to copy.

- name: move /opt to new partition
      become: true
      synchronize:
        src: /opt/
        dest: /mnt/opt
      delegate_to: "{{ inventory_hostname }}"

So basically the initial answer was right but you needed to delete the wildcards "*" and the slash on dest path. Also, you should add the deletion of files on /opt/

Upvotes: 3

Related Questions