Skip to content

Instantly share code, notes, and snippets.

@PrashantBhatasana
Last active November 7, 2019 08:41
Show Gist options
  • Save PrashantBhatasana/b77bafbae93e5f14a174a9b3a08ddca6 to your computer and use it in GitHub Desktop.
Save PrashantBhatasana/b77bafbae93e5f14a174a9b3a08ddca6 to your computer and use it in GitHub Desktop.
This is a Demo Ansible playbook script to pull the latest changes and install new dependences with PM2 start and stop.
---
- name: ANSIBLE - Configure Node server
hosts: SampleApp-Server
become: true
become_method: sudo
become_user: nodejs
vars:
node_version: 6.9.1
tasks:
- name: SERVER | Update the software package repository
yum:
name: "*"
update_cache: yes
- name: SERVER | Ensure repo is up-to-date
git:
repo: "https://github.com/prashant-bhatasana/Node.git"
dest: "/home/nodejs/Node/"
depth: 1
force: yes
accept_hostkey: yes
update: yes
- name: SERVER | Stop pm2 service
shell: "cd /home/nodejs/Node && source ~/.nvm/nvm.sh && pm2 stop 1"
- name: SERVER | Install node dependencies
shell: cd /home/nodejs/Node && source ~/.nvm/nvm.sh && npm install
- name: SERVER | Start pm2 service
shell: "cd /home/nodejs/Node && source ~/.nvm/nvm.sh && pm2 start 1"
[demo-server-1]
10.86.485.123 ansible_ssh_user=root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment