CyberKeeda In Social Media

Ansible script for AWS S3 Bucket automation.


Ansible Script/Tasks/Playbook for AWS S3 Operations.

Within this post, we have a ansible playbook/script that can be used for below tasks.
  1. Create empty s3 buckets, we will use loop to create two empty buckets.
    1. Bucket in specific region.
    2. Bucket with specific tags
    3. Disable bucket public access
  2. Create empty directories within bucket.
Note: galaxy collection must be updated to recent version, in order to use option s3_bucket's updated functions (like. public_access )
$ ansible-galaxy collection install
- hosts: localhost
  connection: local
  gather_facts: False


    - name: Create empty buckets
          name: "{{ item }}"
          state: present
              Name: "{{ item }}"
              Owner: admin
          region: us-west-1
              block_public_acls: true
              ignore_public_acls: true
              block_public_policy: true
              restrict_public_buckets: true
          - cyberkeeda-ansible-bucket1
          - cyberkeeda-ansible-bucket2

    - name: Create empty directories to store artifacts.
          bucket: "{{ item.bucket_name }}"
          object: "{{ item.artifact_dir }}"
          mode: delobj
          - { bucket_name: cyberkeeda-ansible-bucket1, artifact_dir: "/v1/artifcats" }
          - { bucket_name: cyberkeeda-ansible-bucket2, artifact_dir: "/v1/artifcats" }


Will add more to this thread for more s3 specific opeation.

No comments:

Post a Comment

Designed By Jackuna