Skip to content

Create a highly available web server on any cloud provider with Ansible.

Notifications You must be signed in to change notification settings

nleiva/ansible-web-server

Repository files navigation

Highly available Web Application on a cloud provider with Ansible

Ansible Lint

The goal is to provision one or more web server instances behind a load balancer on any cloud provider automatically. See the following image for an example on Azure.

Requirements

Creating a Job Template to Deploy the Web Server(s)

Follow these steps to provision the Web Server(s).

  1. Create a Project for this repo (https://github.com/nleiva/ansible-web-server). I called the Project Azure WebServer in the example below.

  1. Create a Microsoft Azure Resource Manager credential with your Azure service principal parameters.

  1. The number and operating system of the backend servers are defined via the variable vms. Its default value is defined in the vms file. It lists 2 instances; one running centos, and the other one ubuntu (these are the two distributions supported at the moment). You can override this with a new vms definition as an Extra Variable.
vms:
  1: centos
  2: ubuntu
  1. Put all these pieces together in a Job Template pointing to main.yml.

  1. Run the Job Template.

It should look like this when it finishes:

Accessing the Web Server

We distribute the traffic among the instances using an Azure Load Balancer to prevent failure in case any of the virtual machines fail. By default the web server is at http://testbed.eastus.cloudapp.azure.com/. You can modify this with the variable prefix. Its default value is testbed.

This URL will take you to one of the backend VM's. For example:

VM 1

VM 2

Deleting the resources

You can create a similar Job Template pointing to main.yml and pass an extra-var delete=true.

And run it.

Run from an Execution Environment

You can alternatively run this with ansible-navigator.

pip3 install 'ansible-navigator[ansible-core]'

EE Create Web Server

ansible-navigator run main.yml

EE Create Web Server in another cloud provider with a custom domain

ansible-navigator run main.yml -e cloud=aws -e dns_zone=sandbox760.opentlc.com

EE Delete Web Server

ansible-navigator run main.yml -e delete=true

Note: I use podman as my container engine (container-engine). You can change to another alternative in the ansible navigator config file.

Run from the Ansible Core CLI

Check ansible_core.

About

Create a highly available web server on any cloud provider with Ansible.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published