We will learn how to create new S3 bucket using Ansible playbook and automate the execution using Jenkins Pipeline.
Pre-requisites:
- Ansible is installed and Boto is also installed on Jenkins instance
- Ansible plug-in is installed in Jenkins.

- Make sure you create an IAM role with AmazonS3FullAccess policy and attach the role to Jenkins EC2 instance.
- Playbook for creating new S3 bucket needs to be created but you can refer my GitHub Repo
Ansible playbook for AWS S3 bucket creation
Steps:
1. Create Ansible playbook for S3 bucket creation
(Sample playbook is available in my GitHub Repo, you can use that as a reference)
2. Create Jenkins Pipeline
pipeline {
agent any
stages {
stage ("checkout") {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/akannan1087/myAnsibleInfraRepo']]])
}
}
stage('execute') {
steps {
//to suppress warnings when you execute playbook
sh "pip install --upgrade requests==2.20.1"
// execute ansible playbook
ansiblePlaybook 'create-s3.yml'
}
}
}
}
Execute Pipeline
Pipeline Console output
Playbook for creating S3 for your reference:
create-s3.yml
---
- name: provisioning S3 Bucket using Ansible playbook
hosts: localhost
connection: local
gather_facts: False
tags: provisioning
tasks:
- name: create S3 bucket
s3_bucket:
name: myansibles3bucket312
state: present
region: us-east-1
versioning: yes
tags:
name: myansiblebucket
type: example
register: s3_url
- name: Display s3 url
debug: var=s3_url




I really appreciate how clearly you explained using Ansible for S3 bucket provisioning. Displaying the S3 URL at the end is a nice touch to verify success. Will you cover automating deletion or lifecycle policies for buckets in a future post? Also, this resource on AWS cloud is very useful.
ReplyDelete2DBC1EC8E4
ReplyDeleteTakipçi Satın Al
M3u Listesi
MMORPG Oyunlar
Kafa Topu Elmas Kodu
Titan War Hediye Kodu
This is a clear and practical guide. I followed the same process for automating S3 setup on my EC2 Jenkins host, and it worked perfectly. The pipeline example was especially helpful.
ReplyDelete5C95D832B4
ReplyDeleteTelegram Show Kanalı
Skype Şov
Görüntülü Şov