TASK2_RH294_ANSIBLE_DEPLOY_WEBSERVER_ON_AWS_USING_DYNAMIC_INVENTORY

Akshat Soni
4 min readAug 24, 2020

--

TASK DESCRIPTION:-

♦️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.

To perform this task we first create different roles and defined them in the ansible configuration files. Also we have to use the privilege_escalation block to give ec2-user root access.

After this we have created two different roles. One is for launching an ec2 instance on aws cloud using the localhost.

After this the python code will retrieve the Public ip of the launched ec2 instance and with the use of this retrieved ip we can use a dynamic inventory and with its use we can install the httpd package in it.

Here i have showed the roles folder and the code to create a new role.

In the ec2oslaunch role I have multiple files. One file is used to store multiple tasks. And the variable file is encrypted using the ansible-vault command as this file will contain the credentials of my aws account.

This role is used to run the commands on the localhost as it will use the localhost to connect to the aws cloud and launch instances their. We can change the no of instances by changing the count variable value.

I have created a separate folder for running the ansible-playbook. For running the playbook we need to use some special keywords as the variable files are encrypted.

After launching the ec2 instance we can confirm it from the webui and also by logging in we can check that whether the httpd software is installed or not.

Now we have to we can use the ec2.py code to retrieve the public ip of the instance also we need to put the ec2.py file in the ansible_inventory folder.

I have created one more role for installing the httpd package in the ec2 instance using the dynamic inventory.

We can run the apacheconfig playbook to install the package here.

We can check whether the package is installed or not by directly logging into the ec2 instance.

--

--

No responses yet