Objective: This Project automate the provisioning of infrastructure and configuring it with integration of Terraform and Ansible.
Real-time Scenario: Royal Hotel is a globally leading chain of hotels. Recently, as part of scaling up operations, they aim to automate every operation in the hotel. For this, multiple applications are onboarded within all the hotel’s main server. To keep these applications up and running and to scale them appropriately, they need fully managed virtual machines on AWS. They want to have an automated provisioned infrastructure through which they can create a new developer VM and manage some developer configurations on that server.
- Ansible: Ansible automates IT tasks, streamlining configuration management, application deployment, and orchestration. It uses simple, human-readable YAML files called playbooks.
- Terraform: Terraform automates the provisioning and management of infrastructure using declarative configuration files. It supports multiple cloud providers and services, enabling consistent infrastructure deployment and scaling.
- AWS EC2 (Amazon Linux 2023): 5 VMs (5 EC2 Instances)
- AWS VPC, Subnets, Route Table, Security Group, Key Pair
- Java: java-21-amazon-corretto.x86_64 (as task of Ansible Playbook)
- Apache Tomcat-9 Server (as task of Ansible Playbook)
- Install Ansible and Terraform on Master machine of Linux distribution.
- Create a directory as “terraform-multi-instances” and create these files: tomcat-playbook.yaml, ansible.cfg & terraform.tf
- Run the terraform workflow and Ansible playbook commands in sequence.
- Destroy/delete the provisioned resources in the AWS Cloud Infrastructure.
Install Ansible and Terraform on Master machine of Linux distribution
Create an Ansible Playbook with name “tomcat-playbook.yaml” to define tasks for installing Java and then Tomcat-9 on 5 - EC2 Instances
Create Ansible Config file “ansible.cfg”
vi ansible.cfg
Create Terraform Configuration file “terraform.tf”
Run the terraform workflow commands in sequence:
- terraform init
- terraform validate
- terraform plan
- terraform apply -auto-approve
Now navigate to AWS Cloud Infrastructure to check newly provisioned Resources:
5 AWS EC2 Instances (5 VMs) created successfully – screenshot:
AWS VPC got created successfully with required CIDR, Subnet, Route table, Security group:
- Playbook Task: Java-21 was installed on all 5 EC2 instances.
- Playbook Task: Apache Tomcat-9 tar file was downloaded and extracted successfully.
Playbook Task: Tomcat-9 server was installed and started successfully on all the 5 VMs (5 EC2 Instances):
Now destroy/delete the provisioned resources in the AWS Cloud Infrastructure
- terraform destroy -auto-approve
Command got executed successfully and all the terraform provisioned resources have been destroyed.
The above Project with all it's Steps, Files & Settings - automated the provisioning of infrastructure on AWS, to get fully managed Virtual Machines (multiple EC2 instances) and configuring each of the VMs to install multiple applications is met, with the integration of Terraform and Ansible.