Ansible and AWS

Deploy Web-Server on AWS through ANSIBLE!

What is ANSIBLE?

What is an AWS EC2 Instance?

🔰 Task — Deploy Webserver on AWS through Ansible!

♦️ Retrieve the IP Address of instance using dynamic inventory concept.

♦️ Configure the webserver through ansible!

♦️ Create a role for the webserver to customize the Instance and deploy the webpage.

Let’s start the task …

command : pip3 install boto

Step 2 : Create a role for launching the AWS instance.

command : ansible-galaxy role init aws-instance(role _name)

  • Write the code inside tasks/main.yml file of roles , for launching AWS instance.
  • Write the value of access and secret variables inside the vars/main.yml file, which contains AWS_Access_Key and AWS_Secret_Key.
   access: XXXXXXXXXXX
  • Give the path of role inside the ansible configuration file. i.e./etc/ansible/ansible.cfg

Step 3 : Create a playkbook that will connect aws-instance role to launch the instance.

  • Run the playbook in localhost as we don't have public IP of the instance.

command : ansible-playbook aws.yml

The instance has been launched Successfully in AWS …👇

Step 4 : To get the Public IP of instance dynamically in the inventory Download the and ec2.ini files.

command : wget

command : wget

  • Make both file executable file executable.
  • Inside file , change the firstline 👇 to execute the file with proper python interpreter.
  • Provide the Access Credentials i.e. AWS Access Key and Secret Key.

Step 5 : Now , Configure the inventory .

  • Now , We can get the public IP of the instance and it will be able to ping from any source.

command : ansible all — list-hosts

Let’s Configure the Webserver …

Step 6 : Create a role for Configuring webserver inside the EC2 instance.

command : ansible-galaxy role init webserver

Step 7 : Write the code for webserver Configuration in tasks/main.yml file of webserver role.

Step 8 : Create a playkbook that will connect webserver role to configure it.

Now , Run the playbook .

command : ansible-playbook web.yml

As you can see below , Your Webpage has been deployed successfully over the AWS cloud.

Task Completed !!!

Thank you .

Started Learning New Technologies