Effortless Deployment of Project with Ansible & Nginx on AWS

Prerequisite

Before you start, you should already know how to write Ansible playbooks well.
You should have some basic knowledge of Nginx.
You should be comfortable with AWS EC2.

If you’re new to AWS EC2, check out this beginner-friendly …


This content originally appeared on DEV Community and was authored by Amash Ansari

Prerequisite

  1. Before you start, you should already know how to write Ansible playbooks well.
  2. You should have some basic knowledge of Nginx.
  3. You should be comfortable with AWS EC2.

If you're new to AWS EC2, check out this beginner-friendly guide. For more information about Ansible, click here.

Create the EC2 Instances

Set up two EC2 instances for this project: one as the control (worker) node, managed by Ansible, and the other as the managed (worker) node. The control node will use playbooks to configure the managed node and automate the entire deployment process.

Image description

Let's write the playbook

What we're going to do is create a playbook that installs Nginx and starts the service on the worker node. This playbook will be set up and controlled by the control node. Here's the playbook:

-
  name: This is a simple HTML project
  hosts: servers             #Group name that will host this playbook
  become: yes                #Giving sudo privileges
  tasks:
    - name: nginx-install    #This will install the nginx
      apt:
        name: nginx
        state: latest

    - name: nginx-start
      service:                #This will start and enable the nginx service
        name: nginx
        state: started
        enabled: yes

    - name: deploy-app
      copy:
        src: ../index.html     #Give path to the file
        dest: /var/www/html/   #Nginx will serve our file from this specific location

Our next task is straightforward: run this playbook on the control node using the terminal and wait for Ansible to configure and deploy an end-to-end application with a single click.

If you'd like to access my "index.html" file, just click here.

Execute the playbook

To run the playbook, use the following command:

ansible-playbook <playbook-name>

You'll see some output similar to this:

Image description

Check the project by accessing

Finally, ensure the project is up and running by accessing it on the default Nginx port, which is 80.

Image description


This content originally appeared on DEV Community and was authored by Amash Ansari


Print Share Comment Cite Upload Translate Updates
APA

Amash Ansari | Sciencx (2024-09-10T18:30:24+00:00) Effortless Deployment of Project with Ansible & Nginx on AWS. Retrieved from https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/

MLA
" » Effortless Deployment of Project with Ansible & Nginx on AWS." Amash Ansari | Sciencx - Tuesday September 10, 2024, https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/
HARVARD
Amash Ansari | Sciencx Tuesday September 10, 2024 » Effortless Deployment of Project with Ansible & Nginx on AWS., viewed ,<https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/>
VANCOUVER
Amash Ansari | Sciencx - » Effortless Deployment of Project with Ansible & Nginx on AWS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/
CHICAGO
" » Effortless Deployment of Project with Ansible & Nginx on AWS." Amash Ansari | Sciencx - Accessed . https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/
IEEE
" » Effortless Deployment of Project with Ansible & Nginx on AWS." Amash Ansari | Sciencx [Online]. Available: https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/. [Accessed: ]
rf:citation
» Effortless Deployment of Project with Ansible & Nginx on AWS | Amash Ansari | Sciencx | https://www.scien.cx/2024/09/10/effortless-deployment-of-project-with-ansible-nginx-on-aws/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.