-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Your Name <[email protected]>
- Loading branch information
Your Name
committed
Jan 6, 2024
1 parent
5e9ed74
commit 35c7972
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
Vagrant.configure("2") do |config| | ||
|
||
# Do not pay attention to this parameter | ||
if Vagrant.has_plugin?("vagrant-vbguest") | ||
config.vm.provider :virtualbox do |vb| | ||
config.vbguest.auto_update = false | ||
end | ||
end | ||
|
||
config.ssh.insert_key = false | ||
|
||
# Define the nodejs_server VM | ||
config.vm.define "nodejs_server" do |server| | ||
# Specify the Vagrant box to use | ||
server.vm.box = "ubuntu/bionic64" | ||
# Specify the VM ip address | ||
config.vm.network "forwarded_port", guest: 3000, host: 3000 | ||
# Specify the VM specs when using the Virtualbox provisioner | ||
server.vm.provider "virtualbox" do |vb| | ||
vb.name = "nodejs.server.local" | ||
# VM RAM in MB | ||
vb.memory = 2048 | ||
# VM CPUs | ||
vb.cpus = 1 | ||
end | ||
config.vm.provider "vmware_desktop" do |vmware| | ||
vmware.vmx["memsize"] = "2048" | ||
vmware.vmx["numvcpus"] = "1" | ||
end | ||
end | ||
|
||
# Use Vagrant Ansible provisioner | ||
config.vm.provision "ansible_local" do |ansible| | ||
# The path to the playbooks entry point | ||
ansible.version = "2.10" | ||
ansible.playbook = "ansible/playbooks/install.yml" | ||
# Only run the roles with these tags | ||
ansible.tags = "install" | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
- name: Install Node.js and MongoDB | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: Update apt cache | ||
apt: | ||
update_cache: yes | ||
|
||
- name: Install Node.js and npm | ||
apt: | ||
name: "{{ item }}" | ||
state: present | ||
loop: | ||
- nodejs | ||
- npm | ||
|
||
- name: Install MongoDB | ||
apt: | ||
name: mongodb | ||
state: present | ||
|
||
- name: Start MongoDB service | ||
service: | ||
name: mongodb | ||
state: started | ||
|
||
- name: Clone Node.js Application from GitHub | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: Clone the GitHub repository | ||
git: | ||
repo: https://github.com/deepanshu-yadav/devopsprojects23.git | ||
dest: /opt/nodejs-app | ||
register: git_clone | ||
|
||
- name: Install npm dependencies | ||
command: npm install | ||
args: | ||
chdir: /opt/nodejs-app | ||
|
||
- name: Check Health of Node.js Application | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: Check if Node.js app is running | ||
shell: ps aux | grep 'node /opt/nodejs-app/server.js' | grep -v grep | ||
register: node_app_status | ||
failed_when: node_app_status.rc != 0 | ||
|
||
- name: Check if MongoDB is running | ||
service_facts: | ||
register: services | ||
- assert: | ||
that: | ||
- "'mongodb' in services.services" | ||
- "'running' in services.services.mongodb.state" | ||
fail_msg: "MongoDB is not running." |