Ansible Script/Tasks/Playbook for AWS S3 Operations.
Within this post, we have a ansible playbook/script that can be used for below tasks.- Create empty s3 buckets, we will use loop to create two empty buckets.
- Bucket in specific region.
- Bucket with specific tags
- Disable bucket public access
- Create empty directories within bucket.
Note: amazon.aws 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 amazon.aws
---
- hosts: localhost
connection: local
gather_facts: False
tasks:
- name: Create empty buckets
s3_bucket:
name: "{{ item }}"
state: present
tags:
Name: "{{ item }}"
Owner: admin
region: us-west-1
public_access:
block_public_acls: true
ignore_public_acls: true
block_public_policy: true
restrict_public_buckets: true
with_items:
- cyberkeeda-ansible-bucket1
- cyberkeeda-ansible-bucket2
- name: Create empty directories to store artifacts.
aws_s3:
bucket: "{{ item.bucket_name }}"
object: "{{ item.artifact_dir }}"
mode: delobj
with_items:
- { bucket_name: cyberkeeda-ansible-bucket1, artifact_dir: "/v1/artifcats" }
- { bucket_name: cyberkeeda-ansible-bucket2, artifact_dir: "/v1/artifcats" }
- Create empty s3 buckets, we will use loop to create two empty buckets.
- Bucket in specific region.
- Bucket with specific tags
- Disable bucket public access
- Create empty directories within bucket.
Note: amazon.aws 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 amazon.aws
--- - hosts: localhost connection: local gather_facts: False tasks: - name: Create empty buckets s3_bucket: name: "{{ item }}" state: present tags: Name: "{{ item }}" Owner: admin region: us-west-1 public_access: block_public_acls: true ignore_public_acls: true block_public_policy: true restrict_public_buckets: true with_items: - cyberkeeda-ansible-bucket1 - cyberkeeda-ansible-bucket2 - name: Create empty directories to store artifacts. aws_s3: bucket: "{{ item.bucket_name }}" object: "{{ item.artifact_dir }}" mode: delobj with_items: - { 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