Ansible Copy Files

I asked this on Stackoverflow and was wondering if anyone had experience with this problem:

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 multiple times and hence very slow (there is a huge list of files to copy)

You can silence the messages by setting "warn: false" on the command task.
Can also be turn off globally by setting "command_warnings = False" in ansible.cfg

Oh sure, but I don’t really have a problem with the message itself. I am just wondering: if ‘Ansible’ thinks there is a better way to do it (because of a module the project provides), what am I doing wrong with my configuration that I cannot achive what I want in an officially supported way. Is, what I am trying to do, beyond Ansible’s scope? If not, how should I do it? If yes, is there a better tool to achieve this?

Oh sure, but I don't really have a problem with the message itself. I am
just wondering: if 'Ansible' thinks there is a better way to do it (because
of a module the project provides), what am I doing wrong with my
configuration that I cannot achive what I want in an officially supported
way.

The message is just printed since you are using rsync in command module.
It doesn't mean that Ansible has analysed your code and thinks there is a better way to do it.
Think of it a message to someone that doesn't now synchronize exist.

The documentation clearly says synchronize is a basic wrapper around rsync, from the documentation:
"You still may need to call rsync directly via command or shell depending on your use case. synchronize does not provide access to the full power of rsync, but does make most invocations easier to follow."

Is, what I am trying to do, beyond Ansible's scope?

No, but the module have not implemented everything and what you are trying to do is probably not implemented yet.
It OK to use command and shell module, they are included for a reason.

If not, how should
I do it? If yes, is there a better tool to achieve this?

- If you have the skills, you could make the changes to the module and send a pull request on Github.
- Alternative is to pay someone to do it for you.
- Or just use command module and rsync.

“You still may need to call rsync directly via command or shell
depending on your use case. synchronize does not provide access to the
full power of rsync, but does make most invocations easier to follow.”

That is good to know.

Is, what I am trying to do, beyond Ansible’s scope?

No, but the module have not implemented everything and what you are
trying to do is probably not implemented yet.
It OK to use command and shell module, they are included for a reason.

Right!

If not, how should
I do it? If yes, is there a better tool to achieve this?

  • If you have the skills, you could make the changes to the module and
    send a pull request on Github.
  • Alternative is to pay someone to do it for you.
  • Or just use command module and rsync.

Sounds good, thanks!