Launch of an instance and configure as Web Server: using ANSIBLE
Prerequisites:-
- Virtaul Box
- RHEL 8 ISO.
- I have deployed RHEL ISO and I’ll use it as an ansible controller.
I’ve done the minimal installation, Hence need to install some required packages manually.
Ansible configuration steps:-
- In you install rhel 8 with minimal install, you have to install python manually:-
Why I installed Python?
Because Ansible has been derived from the Python language.
Now we need to install ansible using pip3 (python). How it is getting installed?
Remember we created an additional repo “epel-release-latest-8.noarch.rpm”
Let’s install Ansible:
Problem Statement : Deploy Web Server on AWS through ANSIBLE!
♦️Provision EC2 instance through ansible.
♦️Retrieve the IP Address of instance using dynamic inventory concept.
♦️Configure the web server through ansible!
♦️Create role for webserver to customize the Instance and deploy the webpage to root directory.
Step 1 : install boto and ansible library.
Pip3 install boto3
pip3 install ansible
Step 2 : key pawan.pem
place the key file in “/etc/ansible/” directory.
change the permission of this file to 400 (read-only).
Step 3 : configure ansible.
Step 4 : create directories for playbook, roles and inventory
mkdir playbook roles inventory
Step 5 : download ansible dynamic Inventory script for EC2 in inventory folder.
Make these file executable:
Step 6 : Export your aws credentials
export AWS_ACCESS_KEY_ID="accesskey" export AWS_SECRET_ACCESS_KEY="secretkey" export AWS_DEFAULT_REGION="ap-south-1"
Step 7 : create role in roles folder.
ansible-galaxy init ec2 ansible-galaxy init web_server
Step 8 : launch an ec2 instance (Amazon Linux AMI 2)
Step 9 : write playbook for launching ec2 in playbook folder.
Step 9 : configure role for the web_server.
task code to deploy webserver on AWS
template for IP and port configuration of webserver
Handler for the code
variables for the code
Step 11 : write playbook to configure web_server in playbook folder.
playbook for webserver configuration
configure webserver
configuring…
Note : Don’t forget to allow 8080 port in your Security group.
Here we go, Web Server is ready !!!
Sample website launched in the AWS instance.
Thanks For Reading!!