Ansible EC2 Plugin

For those learning and using Ansible, this is a quick document on how to set up and use the Ansible dynamic inventory plugin for AWS EC2 host management.

Ansible comes with various dynamic inventory plugins one of those being aws_ec2. The aws_ec2 plugin is a great way to manage AWS EC2 Linux instances without having to maintain a standard local inventory. This will allow for easier Linux automation, configuration management, and infrastructure as code of AWS EC2 instances.

In order to use the aws_ec2 plugin, you will need the boto3 and botocore Python packages installed on an Ansible controller server.


For those learning AWS/AWS CLI, CloudFormation is a tool for building infrastructure with AWS.

Here is a very simple document on how to use CloudFormation to build an AWS EC2 Linux instance and execute a bash script from CloudFormation against the newly created Linux instance. This is a counterpart document to Learning how to execute a Bash script from Terraform.

Executing a bash script from CloudFormation can be used to configure the newly created server or for any other purpose.

The example below will show how to execute a script named setup-lnxcfg-user; this bash script will prepare the newly created…


For those learning AWS/AWS CLI, Terraform is a tool for building infrastructure with various technologies including AWS, Azure, GCP, and vSphere.

Here is a very simple document on how to use Terraform to build an AWS EC2 Linux instance and then execute a bash script from Terraform against the newly created instance. The bash script will be executed from Terraform as a provisioner.

Executing a bash script from Terraform can be used to configure the newly created server or for any other purpose.

The example below will show how to execute a script named setup-lnxcfg-user; this bash script will prepare…


For those learning Ansible with AWS/AWS CLI this is a quick and short document on how create an AWS VPC, Subnet, Security Group, and Access Control List using Ansible from within CentOS 7 Linux.

As a quick first step make sure the following are installed on CentOS 7:

yum install python2-pip
pip install awscli
pip install boto
pip install boto3
pip install bs4

The below Ansible Playbook performs the following:

  1. adds a new VPC
  2. creates an internet gateway
  3. creates the subnet
  4. creates the security group for the subnet
  5. creates the network access control list
  6. creates the route table with public…


For those learning Ansible this is a quick and simple document on how to create AWS instances, create and attach AWS volumes, and create an ami using Ansible from CentOS 7 Linux.

As a quick first step make sure the following are install on CentOS 7 Linux:

yum install python2-pip
pip install awscli
pip install boto
pip install boto3
pip install bs4

If upgrading Ansible to the new 2.8 version simply execute:

pip install ansible --upgrade

The following Ansible Playbook will create an AWS instance using the free Amazon Linux ami in the us-east-1 region which is ami-0d19227302e8e4bb5. If using…


For those interested in learning Ansible with Ansible roles, this is a short document on how to install, setup, and use Ansible roles for automation and Configuration Management with CentOS 7 Linux.

For those who have a Chef background, Ansible roles are analogous to Chef Cookbooks with the directory structure predefined for deployment. An Ansible Playbook is the nuts and bolts of getting tasks done and resembles Chef Recipes within a Chef Cookbook.

Ansible Playbooks do not work within a specified universally accepted directory structure. …


For those learning Ansible this is a quick document on how to install, setup, and use Ansible for Linux Automation and Configuration Management. In this document you will learn the basics of an Ansible Playbook and learn how to automate such things as systemd unit files, cron files, executing external scripts from an Ansible Playbook, install software, open firewalld ports, add and remove Linux users, configure Linux logical volumes, and much more.

Ansible is similar to Chef and Puppet yet Ansible works without an agent running on the Linux client. …


For those learning AWS/AWS CLI, Terraform is a tool for building infrastructure with various technologies including Amazon AWS, Microsoft Azure, Google Cloud, and vSphere.

Here is an extremely simple document on how to use Terraform to build an AWS VPC along with a Subnet and Network ACL for the VPC.

The below Terraform code was built with Terraform 0.12.16 and consists of two Terraform tf files vpc.tf and variables.tf.

vpc.tf is the actual configuration file and the variables are declared within the variables.tf file.

vpc.tf:

# vpc.tf 
# Create VPC/Subnet/Security Group/Network ACL
provider "aws" { version = "~> 2.0" access_key =…


For those learning AWS/AWS CLI Terraform is a tool for building infrastructure with various technologies including AWS.

Here is a very simple document on how to use Terraform to build an AWS EC2 Linux instance.

Terraform uses the Amazon Command Line Interface (AWS CLI) so make sure you have this setup and enabled on your local Linux box

Download terraform: https://www.terraform.io/downloads.html. I downloaded the 64bit Linux version, unzipped the archive file, and copied the terraform executable into my /usr/local/bin directory. Now the terraform command is in my path.

Create a directory to store and use terraform files:

mkdir -p ~/terraform/CreateInstance


For those learning AWS/AWS CLI this is a quick document on how create an AWS VPC and Subnet using the AWS CLI (AWS Command Line Interface) from a Linux/Bash script.

The below bash script performs the following:

  1. adds a new VPC
  2. names the VPC
  3. adds dns support
  4. adds a dns hostname
  5. creates an internet gateway
  6. names the internet gateway
  7. creates the subnet
  8. names the subnet
  9. enables public ip on the subnet
  10. creates the security group for the subnet
  11. names the security group
  12. enables port 22 for ssh
  13. creates the route table
  14. names the route table
  15. adds route to the internet…

Bradley Simonin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store