Skip to content

This GitHub repository showcases an Ansible-based solution for effortlessly deploying and managing multiple Ubuntu servers hosting Apache web servers on AWS. Enhance scalability and reduce manual configuration efforts.

Notifications You must be signed in to change notification settings

harshartz/Ansible-Orchestrated-Apache-Web-Hosting-on-AWS-EC2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Ansible-Orchestrated-Apache-Web-Hosting-on-AWS-EC2

This project demonstrates the setup and configuration of a multi-server environment using Ansible on AWS EC2. The goal of this project is to host an Apache server on multiple Ubuntu servers.

Prerequisites

  • AWS account with appropriate permissions to launch EC2 instances.
  • Ansible installed on the master server.

Setup

  1. Launch Ubuntu EC2 instances on AWS:

    • Launch four instances with the following names: master, server-1, server-2, server-3.
    • Ensure that all instances are launched with the same configuration, key pair, and security group.
  2. Access the master server:

    • Connect to the master server using SSH.
    • Install Ansible on the master server.
  3. Configure SSH access:

    • In the path ./ssh, create a file named my-key.
    • Copy and paste the key pair that you used while launching the servers into this file.
    • Run the following command:
      $ cd ./ssh
      $ vi my-key
      # Copy and paste the key pair into the file, save, and exit.
      
  4. Configure inventory file:

    • By default, the inventory file is stored in /etc/ansible/hosts. If it doesn't exist, create a new folder named ansible and inside that folder, create the inventory file named hosts.
    • Run the following commands:
      $ sudo mkdir /etc/ansible
      $ sudo vi /etc/ansible/hosts
      
    • Add the details of the nodes in the following format:
      [nodes]
      server-1 ansible_host=<server-1 IP address>
      server-2 ansible_host=<server-2 IP address>
      server-3 ansible_host=<server-3 IP address>
      
  5. Check inventory information:

    • Run the following command to display the inventory information:
      $ ansible-inventory --list -y -i /etc/ansible/hosts
      
  6. Ping all nodes:

    • Run the following command to ping all nodes:
      $ ansible all -m ping -i /etc/ansible/hosts --private-key=~/.ssh/my-key
      
  7. Configure playbook:

    • Create a file named test.yaml in the Ansible project directory.
    • Write the necessary Ansible playbook code to install and configure Apache on the target nodes.
    • Run the following command:
      $ vi test.yaml
      # Add the playbook code, save, and exit.
      
  8. Execute the playbook:

    • Run the following command from the Ansible project directory:
      $ ansible-playbook test.yml -i /etc/ansible/hosts --private-key=~/.ssh/my-key
      
  9. Verify the setup:

    • Access the IP addresses of server-1, server-2, and server-3 in a web browser.
    • You should see the default Apache page indicating a successful deployment.

Screenshot 2023-06-18 170135

About

This GitHub repository showcases an Ansible-based solution for effortlessly deploying and managing multiple Ubuntu servers hosting Apache web servers on AWS. Enhance scalability and reduce manual configuration efforts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published