{"id":18722443,"url":"https://github.com/nleiva/ansible-web-server","last_synced_at":"2025-06-17T15:41:15.979Z","repository":{"id":46578860,"uuid":"409256923","full_name":"nleiva/ansible-web-server","owner":"nleiva","description":"Create a highly available web server on any cloud provider with Ansible.","archived":false,"fork":false,"pushed_at":"2023-06-27T18:18:36.000Z","size":5483,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T07:34:19.541Z","etag":null,"topics":["ansible","aws","azure","gcp"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nleiva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-22T15:25:25.000Z","updated_at":"2024-08-13T16:04:48.000Z","dependencies_parsed_at":"2022-07-20T06:17:09.748Z","dependency_job_id":null,"html_url":"https://github.com/nleiva/ansible-web-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Fansible-web-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Fansible-web-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Fansible-web-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Fansible-web-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nleiva","download_url":"https://codeload.github.com/nleiva/ansible-web-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586264,"owners_count":21128995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","aws","azure","gcp"],"created_at":"2024-11-07T13:41:27.538Z","updated_at":"2025-04-12T14:51:42.202Z","avatar_url":"https://github.com/nleiva.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Highly available Web Application on a cloud provider with Ansible\n[![Ansible Lint](https://github.com/nleiva/ansible-web-server/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/nleiva/ansible-web-server/actions/workflows/ansible-lint.yml)\n\nThe 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. \n\n\u003cp align=\"center\"\u003e\n\u003cimg height=\"400\" src=\"./pictures/webserver.svg\"\u003e\n\u003c/p\u003e\n\n## Requirements\n\n- [AWS](aws.md)\n- [Azure](azure.md)\n- [GCP](gcp.md)\n\n\n## Creating a Job Template to Deploy the Web Server(s)\n\nFollow these steps to provision the Web Server(s).\n\n1. Create a Project for this repo (`https://github.com/nleiva/ansible-web-server`). I called the Project `Azure WebServer` in the example below.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_project.png\"\u003e\n\u003c/p\u003e\n\n2. Create a [Microsoft Azure Resource Manager](https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#microsoft-azure-resource-manager) credential with your [Azure service principal parameters](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal).\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_Azure_cred.png\"\u003e\n\u003c/p\u003e\n\n3. The number and operating system of the backend servers are defined via the variable `vms`. Its default value is defined in the [vms file](vars/vms.yml). 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](https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html#extra-variables).\n\n```yaml\nvms:\n  1: centos\n  2: ubuntu\n```\n\n4. Put all these pieces together in a Job Template pointing to [main.yml](main.yml).\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_create_job.png\"\u003e\n\u003c/p\u003e\n\n5. Run the Job Template.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_create_run.png\"\u003e\n\u003c/p\u003e\n\nIt should look like this when it finishes:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_create.png\"\u003e\n\u003c/p\u003e\n\n## Accessing the Web Server\n\nWe distribute the traffic among the instances using an [Azure Load Balancer](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-overview) 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`.\n\nThis URL will take you to one of the backend VM's. For example:\n\n### VM 1\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/centos.png\"\u003e\n\u003c/p\u003e\n\n### VM 2\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/ubuntu.png\"\u003e\n\u003c/p\u003e\n\n## Deleting the resources\n\nYou can create a similar Job Template pointing to [main.yml](main.yml) and pass an extra-var `delete=true`.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_delete_job.png\"\u003e\n\u003c/p\u003e\n\nAnd run it.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/tower_delete.png\"\u003e\n\u003c/p\u003e\n\n## Run from an Execution Environment\n\nYou can alternatively run this with [ansible-navigator](https://github.com/ansible/ansible-navigator#installing).\n\n```bash\npip3 install 'ansible-navigator[ansible-core]'\n```\n\n### EE Create Web Server\n\n```bash\nansible-navigator run main.yml\n```\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/navigator_create.png\"\u003e\n\u003c/p\u003e\n\n#### EE Create Web Server in another cloud provider with a custom domain\n\n```bash\nansible-navigator run main.yml -e cloud=aws -e dns_zone=sandbox760.opentlc.com\n```\n\n### EE Delete Web Server\n\n```bash\nansible-navigator run main.yml -e delete=true\n```\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./pictures/navigator_delete.png\"\u003e\n\u003c/p\u003e\n\n**Note**: I use [podman](https://podman.io/) as my container engine (`container-engine`). You can change to another alternative in the ansible [navigator config file](ansible-navigator.yml).\n\n## Run from the Ansible Core CLI\n\nCheck [ansible_core](ansible_core.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnleiva%2Fansible-web-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnleiva%2Fansible-web-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnleiva%2Fansible-web-server/lists"}