# Ansible Copy Files

**URL:** <https://forum.ansible.com/t/ansible-copy-files/22772>\
**Category:** Ansible Project\
**Created:** [October 11, 2016, 8:31pm UTC](https://forum.ansible.com/t/ansible-copy-files/22772 "2016-10-11T20:31:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![novice1023](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@novice1023](https://forum.ansible.com/u/novice1023)\
**Post date:** [October 11, 2016, 8:31pm UTC](https://forum.ansible.com/t/ansible-copy-files/22772/1 "2016-10-11T20:31:36Z")

</div>

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)

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

```

My playbook:

```auto
#!/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:

```auto
./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)

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 11, 2016, 8:43pm UTC](https://forum.ansible.com/t/ansible-copy-files/22772/2 "2016-10-11T20:43:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![novice1023](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@novice1023](https://forum.ansible.com/u/novice1023)\
**Post date:** [October 11, 2016, 8:49pm UTC](https://forum.ansible.com/t/ansible-copy-files/22772/3 "2016-10-11T20:49:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 12, 2016, 9:28am UTC](https://forum.ansible.com/t/ansible-copy-files/22772/4 "2016-10-12T09:28:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![novice1023](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@novice1023](https://forum.ansible.com/u/novice1023)\
**Post date:** [October 12, 2016, 2:30pm UTC](https://forum.ansible.com/t/ansible-copy-files/22772/5 "2016-10-12T14:30:19Z")

</div>

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