Launching Instance and Configuring the Webserver Using Ansible:-
Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.
Task-
Statement - Deploy Webserver on AWS through Ansible!
♦️Provision EC2 instance through ansible.
♦️Retrieve the IP Address of instance using dynamic inventory concept.
♦️Configure the webserver through ansible!
♦️Create a role for the webserver to customize the Instance and deploy the webpage.
Let's Start the Practical Part:-
Step1- First of all, we have to install boto before launching the instance.
pip3 install boto
Step2- Now, we have to create a role for launching the instance on the top of AWS.
mkdir /etc/myroles cd /etc/myroles ansible-galaxy init ec2_role
Step3- Inside the vars/main.yml file, we have to pass AWS Access Key and Secret Key. Provide Access key inside "myuser" variable and Secret key inside "mypass" variable -
vim vars/main.yml myuser: XXXXXXXXXXX mypass: XXXXXXXXXXX
Step4- Inside ansible config file.
vim /etc/ansible/ansible.cfg
cd vim ec2.yml
Step5- Now, we have to run the ansible playbook using below command.
ansible-playbook ec2.yml
OUTPUT OF Step5 -
Step6- To get the Instance Ip dynamically in the inventory, we have to download ec2.py and ec2.ini files.
mkdir /mydb cd /mydb
Inside ec2.py, just change one line => #!/usr/bin/python3
export AWS_REGION='ap-south-1' export AWS_ACCESS_KEY_ID='XXXXXXXXXXX' export AWS_SECRET_ACCESS_KEY='XXXXXXXXXXX'
Step7- Now inside the ansible config file, make these changes-
ansible all --list-hosts
Step8- Now, for configuring the webserver inside the EC2 instance -
cd /etc/myroles ansible-galaxy init Webserver
cd vim web.yml
Step9- For running the ansible playbook -
ansible-playbook web.yml
OUTPUT :- Now, on the Browser give the Public IP of the EC2 Instance.
That's All !!
THANKS FOR READING!!!!