/NGINX_Static_on_Ubuntu_in_AWS_using_Ansible

Deploy an NGINX Web Server on Ubuntu in AWS using Ansible

Primary LanguageHTMLMIT LicenseMIT

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.

Overview

Quick Start

  1. Clone this repository:

    git clone https://github.com/1homas/NGINX_Static_on_Ubuntu_in_AWS_using_Ansible.git
  2. 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.

  3. 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
  4. Run the Ansible playbook:

    ansible-playbook playbook.yaml
  5. View the host inventory in AWS by groups:

    ansible-inventory --graph
  6. 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}
  7. 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 server
  • terminate.yaml : delete all AWS resources associated tagged for the project
  • ansible.show_vars.yaml : playbook to show Ansible variables for debugging
  • aws.show.yaml : show all AWS resources for the current AWS IAM user
  • nginx.restart.yaml : restart the nginx server remotely
  • nginx.sync.yaml : synchronize the nginx server site files and configuration then restart

License

This repository is licensed under the MIT License.