Launch Web-Server On AWS using Automation

What is AWS?

→ AWS stands for Amazon Web Services, It is is a comprehensive, evolving cloud computing platform provided by Amazon that includes a mixture of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings. AWS services can offer an organization tools such as compute power, database storage and content delivery services.

AWS compute

AWS offers a variety of compute instances that allow companies to quickly scale up or scale down based on need. Two of the most commonly used AWS computing services are Amazon Elastic Compute Cloud (EC2) and Amazon Elastic Load Balancing.

How AWS works

AWS is separated into different services; each can be configured in different ways based on the user’s needs. Users should be able to see configuration options and individual server maps for an AWS service.

What Is Ansible ?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually. Automation simplifies complex tasks, not just making developers’ jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency. And Ansible, as noted above, is rapidly rising to the top in the world of automation tools.

Ansible Working

Ansible is basically build using Python, but ansible playbooks are written in Yaml language and the format in which ansible display or stores information is Json format,

Ad-hoc Commands

Advantages of Ansible

  • Free: Ansible is an open-source tool.
  • Very simple to set up and use: No special coding skills are necessary to use Ansible’s playbooks (more on playbooks later).
  • Powerful: Ansible lets you model even highly complex IT workflows.
  • Flexible: You can orchestrate the entire application environment no matter where it’s deployed. You can also customize it based on your needs.
  • Agentless: You don’t need to install any other software or firewall ports on the client systems you want to automate. You also don’t have to set up a separate management structure.
  • Efficient: Because you don’t need to install any extra software, there’s more room for application resources on your server.

Ansible’s Features and Capabilities

→ Configuration Management

TASK DESCRIPTION

In this task I tried to automate each and every point of work which we need to perform manually while launching a server over the AWS or any other cloud services such as GCP may be in future if possible I will be showing you all how to manage GCP using Ansible.

vars/main.yml     → Variable declaration
template/main.yml Dynamic Files
tasks/main.yml
here main working of the role to be written
handlers/main.yml → tasks that you want to run or to be called when some condition meets
README.md → Is used in the role for instruction or as description file of the role for the user to make changes or how to use that role.
we have other folders to but right now knowing about them not required for completing this task
Ansible playbook for running above roles
Address of Conf file of Ansible
Underlines are very important for ansible to be used while using for AWS
->In the above file, we specified the inventory folder as /hosts [which contain all the info required for ansible to connect to a Managed Node] ---->remote_user for telling ansbile to go as a user ec2-user 
-> roles_path= used to specify path for ansible to search for all the roles used inside the playbook in that particular folder
->private_key_file= is specified for ansible so that AWS should grant access to ansible for making changes inside the AWS cloud instance.
Command given below I run in /hosts folder which I passed to ansible as it's inventory folder now use the command to fetch the required file.
wget https://raw.githubusercontent.com/onkar2701/ansible-task-2/master/ec2.py
wget https://raw.githubusercontent.com/onkar2701/ansible-task-2/master/ec2.ini
#!/usr/bin/python3
chmod +x ec2.py
chmod +x ec2.ini
Commands need to be run inside the /root folder
export EC2_INI_PATH=path_of_ec2.ini_file
export AWS_ACCESS_KEY_ID="aws_access_key"
export AWS_SECRET_ACCESS_KEY="aws_secret_key"
export AWS_REGION='app-south-1'
chmod 400 <keyaddress/keyname.pem>
For showing error I am running an false playbook
using command
ansible-playbook --ask-vault-pass ec2-test2.yml
chmod +x /hosts/host
ansible-playbook --ask-vault-pass <playbook>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store