Using Ansible to configure NGINX on Ubuntu and host a static website
Disclosure. This page contains links to products that may earn us a small commission at no extra cost to you, should you click on them and make a purchase.
Read full disclosure.
This tutorial will demonstrate how to write an Ansible playbook so that you can automate the installation and configuration of NGINX on a Ubuntu Server. The playbook will install NGINX, remove the default website, create a new virtual host and deploy a static website.
Before we begin you will need to have installed Ansible on your local machine and have access to a remote Ubuntu server.
The following steps have been tested with Ansible v2.9.11 running on a MacBook Pro with a clean installation of Ubuntu Server 18.04 running as a VM on
VMware Fusion*. The steps will also work on a
DigitalOcean* droplet. Click here to read how to deploy a droplet using Ansible.
Once you have installed Ansible and have setup your Ubuntu server, add the IP address along with the following hostnames to your local hosts file.
Step 1: Create Inventory File
First, we will create a folder to store the Ansible files in.
mkdir ansible && cd ansible
Create a file called inventory.yml then add the following: