Deploying Web Server on AWS by using ANSIBLE!!
Table of contents
No headings in the article.
Task:
Provision EC2 instance through Ansible.
Retrieve the IP Address of the instance using a dynamic inventory concept.
Configure the webserver through Ansible.
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.
Ansible:
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows. It includes declarative language to describe system configuration.
Prerequisites:
Install the boto3 library of Python.
- Command: pip3 install boto3
Steps:
Create an ansible-playbook to launch the ec2 instance.
Create a variable file to store the access key and secrete key to log in to the AWS account.
Secure the file using ansible vault.
Command: ansible vault encrypt <file_name>
Check whether the file is encrypted or not.
Run playbook to launch ec2 instance.
Command: ansible-playbook --ask-vault-pass <file_name>
Go to the AWS console and check whether the instance was created or not
Fetch the instance IP dynamically using the dynamic inventory method in Ansible.
Steps:
Download the Python files script which fetches the IP dynamically.
Make the file executable by providing executable permission
Command: chmod +x ec2.py
Export AWS credentials so that the Python script gets access to the AWS console.
Add the path of the inventory file into the ansible configuration file.
Check the host list.
Command: ansible all --list-hosts
Create an Ansible role which configures the web server over the ec2.
Command to create the role: ansible-galaxy init <role_name>
Add yaml code into the main file from the tasks folder which configures the web server over the ec2 instance.
Now, create the ansible yaml file which gives the information about the role and hosts.
Finally, run the yaml file which provides information about the role and hosts.
Now, check whether the web server is configured or not.
Result:
Thank You for reading!!