Deploying Web Servers with Ansible

This repository contains an Ansible playbook designed to deploy and configure an Nginx web server on multiple nodes, demonstrating the ability to manage heterogeneous environments (Ubuntu and Amazon Linux) in an automated fashion.

Project Description

The objective is to automate the configuration of two identical web servers, each on a node with a different operating system, displaying a custom welcome page.

Technologies Used

  • Ansible: For configuration automation.
  • AWS EC2: As the node provider (1 Ubuntu, 1 Amazon Linux).
  • Multipass: As the host machine to run Ansible.
  • Nginx: As the web server.

Repository Structure

  • instalar_nginx.yml: The main Ansible playbook containing all the tasks.
  • .gitignore: File to exclude the inventory (maquinas) from version control for security purposes.
  • README.md: This file.

How the Playbook Works

The instalar_nginx.yml playbook performs the following actions on all hosts in the inventory:

  1. Determines the Nginx root path: It uses a variable and a condition (when: ansible_os_family == "Debian") to set the correct path (/var/www/html for Ubuntu, /usr/share/nginx/html for Amazon Linux).
  2. Installs Nginx: It uses the ansible.builtin.package module, which transparently manages both apt and yum.
  3. Deploys a welcome page: It copies a custom index.html file that displays information about the node.
  4. Ensures the service is running: It guarantees that Nginx is started and enabled to start on system boot.

How to Use It

  1. Clone this repository.
  2. Create an inventory file (e.g., maquinas) with the IPs and credentials of the nodes.
  3. Run the playbook with the command:
Bashansible-playbook -i maquinas instalar_nginx.yml
Scroll al inicio