Bootstrap FreeKB - Ansible - Upload files to Amazon Web Services (AWS) S3 Buckets using the s3_object module
Ansible - Upload files to Amazon Web Services (AWS) S3 Buckets using the s3_object module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

Prerequisites

s3_object can be used to upload files your Amazon Web Services (AWS) S3 Buckets. 

---
- hosts: localhost
  tasks:
  - name: find files
    find:
      paths: /path/to/directory/that/contains/files/you/want/to/upload/to/S3/bucket
    register: find_files

  - name: append files to the 'files' list
    set_fact:
      files: "{{ files | default([]) + [ item.path ] }}"
    with_items: "{{ find_files.files }}"

  - debug:
      var: files

  - name: upload files to S3 bucket
    amazon.aws.s3_object:
      bucket: "{{ s3_bucket_name }}"
      object: "some/folder/in/your/s3/bucket/{{ item | basename }}"
      src: "{{ item }}"
      mode: put
    with_items: "{{ files }}"
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 26bf3e in the box below so that we can be sure you are a human.