Deploy an NGINX Web Server on Ubuntu in AWS using Ansible
Deploys an NGINX web server instance on Ubuntu in AWS using Ansible. You may deploy this using resources in the AWS Free Tier. If you have never deployed an AWS EC2 instance, you may want to read read Deploy an EC2 Instance from the AWS Console to understand the general process and the AWS virtual private cloud (VPC) components involved beyond the Ubuntu VM with NGINX.
Quick Start
-
Clone this repository:
git clone https://github.com/1homas/NGINX_Static_on_Ubuntu_in_AWS_using_Ansible.git
-
Create your Python environment and install Ansible:
pip install --upgrade pip pip install pipenv pipenv install --python 3.9 pipenv install ansible boto boto3 botocore pipenv shell
If you have any problems installing Python or Ansible, see Installing Ansible.
-
Export your AWS Access & Secret keys into your terminal environment:
export AWS_REGION='us-west-1' export AWS_ACCESS_KEY='AKIAIOSF/EXAMPLE+KEY' export AWS_SECRET_KEY='wJalrXUtnFEMI/K7MDENG/bPxRfi/EXAMPLE+KEY'
or you may source these variables from a file that you keep for multiple projects :
source ~/.env/aws.sh
-
Run the Ansible playbook:
ansible-playbook playbook.yaml
-
View the host inventory in AWS by groups:
ansible-inventory --graph
-
SSH to your new running instance:
⚠ Replace the
{hostname}
with the dynamically assigned public IP address!ssh -i ~/.ssh/nginx_static_www.pem ubuntu@{hostname}
-
When you are done, terminate the instances and delete all resources to prevent surprise AWS bills:
ansible-playbook terminate.yaml
Playbooks
playbook.yaml
: the main playbook to create the serverterminate.yaml
: delete all AWS resources associated tagged for the projectansible.show_vars.yaml
: playbook to show Ansible variables for debuggingaws.show.yaml
: show all AWS resources for the current AWS IAM usernginx.restart.yaml
: restart the nginx server remotelynginx.sync.yaml
: synchronize the nginx server site files and configuration then restart
License
This repository is licensed under the MIT License.