Launch Web-Server On AWS using Automation

What is AWS?

AWS compute

How AWS works

What Is Ansible ?

Ansible Working

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

TASK DESCRIPTION

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