We will learn how to create Ansible Role for provisioning a new EC2 instance in AWS cloud. We will pick a playbook which has all the logic and we will refactor into reusable ansible role.
handlers - handlers are typically used to start, reload, restart, and stop services.
defaults - default variables for the role.
vars - other variables for the role. Vars has the higher priority than defaults.
meta - defines some data / information about this role (author, dependency, versions, examples, etc,.)
tests - test cases if you have any.
- Ansible is installed and Boto is also installed on Ubuntu EC2 instance
- Make sure you create an IAM role with AmazonEC2FullAccess policy and attach the role to EC2 instance.
Add the below two lines in the end of the file:
[localhost]
local
mkdir roles
That's it!! That is how you create a new EC2 instance using Ansible role in AWS cloud.