Configuration of Apache WebServer On AWS EC2 Instances Using Ansible
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.
Amazon Web Services:
Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet.
Steps for provisioning of EC2 instance through ansiblle :
- Installing boto/boto3 :
Ansible depends on the Python module boto3 to communicate with AWS API. So, boto3 needs to be installed on your machine.
pip3 install boto boto3
2. Create ec2 instance on aws from control node.We have to write ec2.yml file as below :
Storing your keys in Ansible vault :
ansible-vault create awspass.yml
Once open, add the following to it:
Once you save the file, all the content will be encrypted. You can verify it as:
3. Now run ec2.yml file to launch ec2 instance.
Now we Can see that Instance On AWS Has Been Launched
4. Now For Proceeding we need IP Of Our Instance Launched on aws . so we can just see and type the ip here in ansible inventory file but i am using dynamic inventory concept using this concept we can get the ip of launched instance on aws using one python program that u can get from ansible github.
Steps to retrieve the IP Address of instance using a dynamic inventory concept.
- First we have to download python code from github using wget which fetch ip addresses.
now make it executable :
chmod +x ec2.py
2. For initiating ec2.py file we have to export region, access key, secret key as:
3. Now configure the inventory as :
4. Now checking all hosts by:
5. Now checking the connectivity between controller node and managed node :
Steps for configuring the webserver through ansible.
- Now For Configuring webserver in aws instance we need to do ssh and for this we will require private key.
♦️Transfer your private key to the controller node by using winscp software.
♦️After this you need to make it accessible.
chmod 600 task2.pemcat task2.pem
2. write playbook for webserver configuration on ec2 instance as:
3. Run the above playbook as:
4. Now, You can check httpd service is active or not on ec2 instance by ssh :
- The above picture show you have successfully deployed your server .