Ansible Copy Files

117 views
Skip to first unread message

novic...@gmail.com

unread,
Oct 11, 2016, 4:31:36 PM10/11/16
to Ansible Project
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,targetsY1, 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)

Kai Stian Olstad

unread,
Oct 11, 2016, 4:43:35 PM10/11/16
to ansible...@googlegroups.com
On 11. okt. 2016 22:31, novic...@gmail.com wrote:
> #!/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

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

--
Kai Stian Olstad

novic...@gmail.com

unread,
Oct 11, 2016, 4:49:31 PM10/11/16
to Ansible Project, ansible-pr...@olstad.com
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?

Kai Stian Olstad

unread,
Oct 12, 2016, 5:29:19 AM10/12/16
to ansible...@googlegroups.com
On 11.10.2016 22:49, novic...@gmail.com wrote:
> 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.

--
Kai Stian Olstad
Message has been deleted

novic...@gmail.com

unread,
Oct 12, 2016, 10:30:19 AM10/12/16
to Ansible Project, ansible-pr...@olstad.com
On Wednesday, October 12, 2016 at 4:29:19 AM UTC-5, Kai Stian Olstad wrote:
On 11.10.2016 22:49, novic...@gmail.com wrote: 

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

Reply all
Reply to author
Forward
0 new messages