1
votes

I am trying to copy a bunch of files from server X (not control machine) to a group of servers, targets: Y1, Y2, ..., Yn (defined in host file)

files:
   '-path
       '- files
            '- file1
            '- file2
            '- dir
                '- file_x

My playbook:

#!/usr/bin/env ansible-playbook
---
vars:
  src_dir: /path/files
hosts: {{ targets }}
tasks:
  - name: copying files
    command: "rsync -avrcz X:{{ src_dir }}/{{ artifacts }} {{ dest_dir }}"

My command line:

./playbook.yml -e '{"targets": "targets", "artifacts" : "{file1,file2,dir/file_x}", "dest_dir": "/yserv/dest/path"}'

This works and I am able to parallelize pretty decently, but I keep getting:

[WARNING]: Consider using synchronize module rather than running rsync

Is there a way to achieve this using synchronize module? Ansible doesn't seem to like bash brace expansion syntax. Passing file list as an array and using with_items is not practical since it makes the whole thing sequential by invoking rsync for every file and hence is very slow (there is a huge list of files to copy)

1
Do you need to copy only those files and not the entire directory structure from files downward? - Xiong Chiamiov
@XiongChiamiov Thanks for responding. Yes that is a very valid question, but I require the destination dir/file hierarchy slightly different. So if the on X I have: /store/a/b/c/{d,e}/{f11,f12...}, there are also files at level /store/a/b say x_1,x_2... on destination I want: /home/xuser/b/{d,e,f1}/{f11,f12,..} and /home/xuser/b/{x_1,x_2..}. Hence, in the actuality, in the brace expansion, I pass {x_1, x_2,c/d,c/e} - Novice User
don't use synchronize module for this, it's buggy even for version 2.3, prefer rsync command - user494599

1 Answers

1
votes

Using rsync in you case is faster. The only down-side is that the task will always return "changed": false even if rsync did not change anything. Synchronize module confirm that "You still may need to call rsync directly via command or shell depending on your use case." Just ignore the warning.