# Copying whole directory from amazon S3 using ansible

**URL:** <https://forum.ansible.com/t/copying-whole-directory-from-amazon-s3-using-ansible/14189>\
**Category:** Ansible Project\
**Created:** [December 20, 2013, 4:16am UTC](https://forum.ansible.com/t/copying-whole-directory-from-amazon-s3-using-ansible/14189 "2013-12-20T04:16:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohan\_Deshpande](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Rohan\_Deshpande](https://forum.ansible.com/u/Rohan_Deshpande)\
**Post date:** [December 20, 2013, 4:16am UTC](https://forum.ansible.com/t/copying-whole-directory-from-amazon-s3-using-ansible/14189/1 "2013-12-20T04:16:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 20, 2013, 2:34pm UTC](https://forum.ansible.com/t/copying-whole-directory-from-amazon-s3-using-ansible/14189/2 "2013-12-20T14:34:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sirk\_Johannsen](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Sirk\_Johannsen](https://forum.ansible.com/u/Sirk_Johannsen)\
**Post date:** [October 28, 2016, 11:06am UTC](https://forum.ansible.com/t/copying-whole-directory-from-amazon-s3-using-ansible/14189/3 "2016-10-28T11:06:03Z")

</div>

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

1. 

**s3:**

**bucket: “{{bucket\_name}}”**  
**object: “{{ item }}”**  
**s3\_url: "{{amazon\_s3\_url}}**  
**dest: “{{ destination\_dir }}/{{ item|basename }}”**  
**mode: get**  
**with\_items: “{{ s3list.s3\_keys }}”**
