DEV Community

arielro85
arielro85

Posted on

Full Stack Deployment with Ansible

A few months ago I started practicing ansible and some Javascript with React and NodeJs.
As a playground im using some EC2 instances in AWS, and I did not want to re configure everything everytime that I test the site . For this I wrote an Ansible playbook that performs all the required actions to get the app online.

High level overview of what it does:

  • Extracts the repository names from the frontend_git_repo and backend_git_repo variables.
  • Updates the system packages and reboots the machine if updates were installed.
  • Installs gnupg and curl, which are required for MongoDB.
  • Sets up the NodeSource repository and installs Node.js.
  • Checks if the MongoDB GPG key is already set up, and if not, it sets it up.
  • Creates a list file for MongoDB and updates the package list.
  • Installs MongoDB and starts the mongod service.
  • Installs pm2 globally, which is a process manager for Node.js applications.
  • Installs the Nginx web server and configures it.
  • Copies the SSH key to the EC2 instance.
  • Clones the frontend and backend repositories from GitHub.
  • Creates a new folder in the backend directory.
  • Deletes the copied SSH key from the EC2 instance.
  • Builds the frontend application and moves it to the appropriate directory.
  • Configures pm2 for the backend application and starts it.
  • Restarts the Nginx service.

All the actions above described , are handled by Ansible and a UI called Ansible Semaphore.

Everything is in this repo where you can find the "Mean Stack playbook" and the Ansible Semaphore Docker comppose file to build the controller.

Image description

I really recommend to use Ansible or any tool you want to avoid spending lot of time installing and configuring test services.

For sure there is lot of room for improvements, but it saves a lot of time.
My humble collaboration:

https://github.com/imaerials/ansible-home-lab

Top comments (1)

Collapse
 
su_subh1 profile image
Subh

I really liked the project.