0

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 }}"
dsollen
  • 6,046
  • 6
  • 43
  • 84

1 Answers1

3

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/

ikora
  • 772
  • 3
  • 16
  • 1
    Any reason you recommend copy over sychornize? I'd think rsync would be less likely to copy files in a different state (permissions, owners etc) then copy – dsollen May 04 '21 at 15:47
  • `copy` should be avoided if you have more than a couple files in your directory to copy recursively (unless you enjoy drinking coffee while you wait it's done or you really don't care how much time it takes) – Zeitounator May 04 '21 at 19:40
  • @Zeitounator point is correct. But the problem is that Synchronize, takes the whole directory including the directory name, if you synchronize the /folder1 to /folder2 it will create /folder1 inside /folder2 and the inside /folder2/folder1/allyourcontent, so it's not the best approach to what he wants to achive. At least to my knowledge maybe there is an option but I don't know about it. If you need performance I would go for synchronize. But as I said I don't know how to synchronize only the contents and not the whole folder. – ikora May 05 '21 at 08:37
  • 1
    This is just a matter of trailing slash or not. See `man rsync`. You can also pass specific options to rsync in the module. – Zeitounator May 05 '21 at 08:39
  • You're right i will update the answer to let only synchronize because its a much better approach. Thanks for your time Zeitounator :) – ikora May 05 '21 at 08:49