Configure Webserver on AWS Cloud by Ansible

Manali Jain
3 min readFeb 13, 2021
CONFIGURE WEB SERVER ON AWS BY USING ANSIBLE

Pre-requisites -

  1. Setup for Dynamic Inventory.
  2. Must have an AWS Cloud account.
  3. Install boto and ec2 package by pip command.
  4. Install ansible on the controller node.
  5. Set ansible configuration file like this -
ansible.cfg

Now let’s start the coding…

HTTPDConf.yml-

  1. First, it will ask for user input.
  2. Configure yum.
  3. Transfer HTTPD Conf file and that will collect data at runtime.
  4. StartHTTPD service.
input from user
Mount DVD and Configure yum
HTTPD Configuration

Ec2.yml-

This file will launch an instance on the EC2 service.

configure EC2 instance

Key.yml-

This file contains Access Key and Secret Key.

The access key and Secret Key

Httpdconf.conf-

This is the HTTPD Configuration file which will pick data while running the code.

Conf file

— — — — — — — — — — — — — — — — — — — —

After writing code run the code by using the command.

First set the access key and secret key by using the command -

Access key — “ export AWS_ACCESS_KEY_ID=’XXXXXXXXXXXXX’ ”

Secret key — “ export AWS_SECRET_ACCESS_KEY=’xxxxxxxxxxxxxxxxxx’ ”

set access key and secret key

Now change the mode of the key.

change mode

Now for securing the credentials use the vault command — “ ansible-vault create key.yml ”

create vault

The key file is secured.

key encrypted

For creating the instance run the ec2.yml file by using the command — “ ansible-playbook — ask-vault-pass ec2.yml ”

launch ec2 instance

The instance is created.

ec2 instance running

List the hosts by using the command — “ ansible all — list-hosts ”

dynamic IP

To check the connectivity first ping the instance by the command — “ ansible all -m ping ”

ping for checking connectivity

Now launch the configure web server by using the command — “ ansible-playbook file.yml ”

Configure Webserver

Access the webpage by using the public URL of the instance.

The webPage is up…

Thank you for reading my article !!

Github Link — https://github.com/manali1230/Configure_Webserver_byAnsible_onAWS.git

--

--

Manali Jain

You are the only one person who can Change Yourself…