Copying whole directory from amazon S3 using ansible

4,807 views
Skip to first unread message

Rohan Deshpande

unread,
Dec 19, 2013, 11:16:48 PM12/19/13
to ansible...@googlegroups.com
I have a script that downloads stuff from amazon S3

Downloading file works perfectly but in one scenario i want to download whole directory from the bucket.

Ansible seems to require file name in object and destination

Is anyone aware of how to do this?

Code to download file from amazon S3

s3: bucket={{bucket_name}} object={{filename_to_download}} dest={{destination_dir}}/{{src_filename}}  s3_url={{amazon_s3_url}} mode=get

Code I tried to download whole dir (want to download all files in current dir)
s3: bucket={{bucket_name}} object=/resource/current/ dest={{destination_dir}}/current/  s3_url={{amazon_s3_url}} mode=get

i get following error

 IOError: [Errno 21] Is a directory: '/destination/current/'


Thanks

James Martin

unread,
Dec 20, 2013, 9:34:39 AM12/20/13
to ansible...@googlegroups.com
The s3 module does not support directory uploads, or any recursion.
For this tasks, I'd recommend using s3cmd --sync or a similar tool and
launching it with the command module.

- James
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Sirk Johannsen

unread,
Oct 28, 2016, 7:06:03 AM10/28/16
to Ansible Project, rohan.d...@permeance.com.au
You can do this in 2 steps:
1.
s3: 
  bucket: "{{bucket_name}}"
  prefix:   "{{path_to_download}}" 
  s3_url:  "{{amazon_s3_url}}
  mode: list
register: s3list

2.
s3:
  bucket: "{{bucket_name}}"
  object:  "{{ item }}" 
  s3_url:  "{{amazon_s3_url}}
  dest:     "{{ destination_dir }}/{{ item|basename }}"
  mode:   get
with_items: "{{ s3list.s3_keys }}"
Reply all
Reply to author
Forward
0 new messages