At Red Hat Tech Day Netherlands 2026 in Bunnik, Fred van Zwieten and Ismail Dhaoui demoed the new Automation Portal in AAP 2.7 — a self-service template gallery where operators click "Start" without knowing where a playbook lives or how it's configured. One of the catalog entries was Cloud - Create S3 Bucket, described as creating a compliant S3 bucket with encryption. Here's a runnable playbook that matches that job.
Example playbook
---
- name: "Cloud - Create S3 Bucket"
hosts: localhost
gather_facts: false
connection: local
vars:
bucket_name: "acme-app-logs-prod"
bucket_region: "eu-west-1"
kms_key_alias: "alias/s3-default"
bucket_tags:
environment: "production"
owner: "platform-team"
cost_center: "cc-4821"
tasks:
- name: Create S3 bucket
amazon.aws.s3_bucket:
name: "{{ bucket_name }}"
region: "{{ bucket_region }}"
state: present
tags: "{{ bucket_tags }}"
- name: Enforce default encryption with KMS
amazon.aws.s3_bucket:
name: "{{ bucket_name }}"
region: "{{ bucket_region }}"
state: present
encryption: "aws:kms"
encryption_key_id: "{{ kms_key_alias }}"
- name: Block all public access
amazon.aws.s3_bucket:
name: "{{ bucket_name }}"
region: "{{ bucket_region }}"
state: present
public_access:
block_public_acls: true
ignore_public_acls: true
block_public_policy: true
restrict_public_buckets: true
- name: Enable versioning for recovery and compliance
amazon.aws.s3_bucket:
name: "{{ bucket_name }}"
region: "{{ bucket_region }}"
state: present
versioning: true
What it does
The playbook builds an S3 bucket in four idempotent steps: create the bucket with baseline tags, turn on default server-side encryption using a KMS key, lock down every public-access setting, and enable versioning. Each task targets the amazon.aws.s3_bucket module and can be re-run safely — running it twice won't recreate the bucket or fail, it just confirms the desired state.
This is exactly the shape of job the Automation Portal template wraps: a platform team pre-builds and tests the playbook, sets survey fields for bucket_name, bucket_region, and tags, and publishes it as "Cloud - Create S3 Bucket." A developer or app owner then clicks Start, fills in a short form, and gets a compliant bucket without ever opening a YAML file or knowing which controller node the job runs from.
Splitting encryption, public-access blocking, and versioning into separate tasks (rather than one giant module call) makes the playbook easier to read in job output and easier to extend — for example, adding a lifecycle policy task later without touching the rest.
Notes / Gotchas
- Credentials: this playbook assumes AWS credentials are supplied via an AAP credential attached to the job template (or environment variables/instance profile when run outside AAP) — don't hardcode
aws_access_key/aws_secret_keyin the play. - KMS key must exist first:
encryption_key_idexpects an existing alias or ARN; the module won't create the key for you. - Bucket names are global: S3 bucket names are unique across all of AWS, not just your account — a survey-driven template should validate or namespace the name to avoid collisions.
- Public access block vs. bucket policy:
public_accesssettings block ACL- and policy-based public exposure, but a bucket policy explicitly granting public reads can still conflict — audit policies separately if compliance requires it. - Collection requirement:
amazon.aws.s3_bucketships in theamazon.awscollection; make sure it's installed in the execution environment the job template uses, or the job will fail at task one with a "couldn't resolve module" error.
Takeaway
A handful of amazon.aws.s3_bucket tasks are enough to produce a tagged, encrypted, locked-down, versioned bucket — and wrapping that playbook in a self-service template, as shown for AAP 2.7's Automation Portal, turns it into a one-click action for anyone who needs storage without needing AWS console access.
Related Articles
- Ansible Playbook Example: Provision an EC2 Instance with Standard Tags
- Ansible Playbook Example: Request an Azure Resource Group with RBAC
- Ansible azure.azcollection Example: Provision Azure ML and Storage Resources