Skip to content

Instantly share code, notes, and snippets.

@baditaflorin
Forked from kbariotis/main.yaml
Last active May 14, 2021 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baditaflorin/02a5fb9f2c96edb7ed4fd386fa1a2648 to your computer and use it in GitHub Desktop.
Save baditaflorin/02a5fb9f2c96edb7ed4fd386fa1a2648 to your computer and use it in GitHub Desktop.
Ansible playbook for deploying a Node.js app to DigitalOcean
- name: DO
hosts: localhost
vars:
project_name: "PUT A NAME FOR YOUR PROJECT HERE"
do_token: "PUT YOUR DIGITAL OCEAN API KEY HERE ==> https://cloud.digitalocean.com/settings/api/tokens"
repository: "PUT YOUR REPOSITORY URL HERE"
- name: NODE | Clone/Pull repo
git:
repo: "{{repository}}"
dest: /var/www
register: git_finished
- name: NODE | Install npm deps
shell: npm i
register: npm_finished
failed_when: '"ERR!" in npm_finished.stderr'
when: git_finished.changed
args:
chdir: /var/www
- name: NODE | Install pm2
npm:
name: pm2
global: yes
production: yes
state: present
- name: NODE | Stop APP
shell: pm2 stop app
args:
chdir: /var/www
ignore_errors: yes
- name: NODE | Start APP
shell: pm2 start server.js --name server
args:
chdir: /var/www
ignore_errors: yes
when: npm_finished.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment