-
-
Save baditaflorin/02a5fb9f2c96edb7ed4fd386fa1a2648 to your computer and use it in GitHub Desktop.
Ansible playbook for deploying a Node.js app to DigitalOcean
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
- 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