Skip to content

UdayParkar/nodejs-deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js App Deployment with Terraform & Ansible

Deploy a Node.js application on AWS EC2 using Terraform for infrastructure and Ansible for application deployment.

Note: The Node.js application code is in a separate repository and will be automatically cloned during deployment.

Prerequisites

  • Terraform installed
  • Ansible installed
  • AWS account with configured credentials
  • AWS key pair (.pem file)
  • Git installed

Setup Instructions

1. Clone Repository

git clone https://github.com/<username>/nodejs-app-deployment.git
cd nodejs-app-deployment

2. Configure Ansible Inventory

Edit ansible/inventory.ini:

[ec2]
ubuntu@<PUBLIC_IP> ansible_ssh_private_key_file=/path/to/your/key.pem ansible_ssh_common_args='-o StrictHostKeyChecking=no'

⚠️ Do NOT commit your .pem file to version control

3. Deploy Infrastructure

cd terraform
terraform init
terraform plan
terraform apply

Type yes when prompted.

4. Deploy Application

cd ../ansible
ansible-playbook -i inventory.ini playbook.yml

5. Access Application

Navigate to: http://<PUBLIC_IP>:3007

Deployment Screenshots

Ansible Deployment

Ansible Playbook Execution

Application Running

Node.js App Live

Project Structure

nodejs-app-deployment/
├── terraform/           # Infrastructure code
├── ansible/            # Configuration & deployment
│   ├── inventory.ini   # Server details
│   └── playbook.yml    # Deployment tasks
└── README.md

Configuration

Update variables directly in your Terraform files as needed for your specific AWS setup.

Troubleshooting

SSH Connection Issues:

  • Check .pem file path in inventory.ini
  • Set correct permissions: chmod 400 your-key.pem
  • Verify EC2 instance is running

Terraform Errors:

  • Confirm AWS credentials are configured
  • Ensure key pair exists in specified region
  • Check AWS permissions

Application Not Loading:

  • Verify security group allows port 3007
  • Check public IP address
  • SSH to instance and verify app status

Cleanup

cd terraform
terraform destroy

Commands Reference

Action Command
Deploy infrastructure terraform apply
Deploy application ansible-playbook -i inventory.ini playbook.yml
Destroy infrastructure terraform destroy
Debug Ansible ansible-playbook -i inventory.ini playbook.yml -vvv

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages