Skip to content

Commit

Permalink
Finalizing purge / install steps for nvm upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
TechDufus committed Jan 3, 2024
1 parent 6367c3c commit 412d50a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
67 changes: 59 additions & 8 deletions roles/nvm/tasks/nvm-install.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
---
- name: Check if NVM is installed
ansible.builtin.command: command -v nvm
ansible.builtin.shell: command -v nvm
changed_when: false
failed_when: false
register: nvm_installed

- name: Check if Node is installed
ansible.builtin.command: command -v node
args:
executable: /bin/bash -i
ansible.builtin.shell: command -v node
changed_when: false
failed_when: false
register: node_installed

- name: Get Installed Node Version
ansible.builtin.command: node --version | cut -c2-
args:
executable: /bin/bash -i
ansible.builtin.shell: node --version | cut -c2-
register: node_version
changed_when: false
failed_when: false
when: node_installed.stdout != ""

- name: Set Node Version
ansible.builtin.set_fact:
node_installed_version: "{{ node_version.stdout }}"
when: node_installed.stdout != ""

- name: Check if Node Update is needed
ansible.builtin.assert:
that:
- node_version.stdout | version(nvm.node.version, '!=')
- node_installed_version is version_compare(nvm.node.version, '!=')
success_msg: "Node Version Needs to be Updated / Reinstalled."
fail_msg: "Node Version is already up to date."
register: node_update_needed
when: node_installed.stdout != ""

Expand Down Expand Up @@ -87,3 +90,51 @@
creates: "/home/{{ global.user }}/.nvm/versions/node/v{{ nvm.node.version }}"
become: true
become_user: "{{ global.user }}"

- name: Install Logrotate
ansible.builtin.include_role:
name: logrotate
tasks_from: logrotate-install.yml
apply:
tags:
- nvm-install
- nvm
when:
- node_update_needed is defined
- node_update_needed

- name: Install PM2
ansible.builtin.include_role:
name: pm2
tasks_from: pm2-install.yml
apply:
tags:
- nvm-install
- nvm
when:
- node_update_needed is defined
- node_update_needed

- name: Install Watchdog
ansible.builtin.include_role:
name: watchdog
tasks_from: watchdog-install.yml
apply:
tags:
- nvm-install
- nvm
when:
- node_update_needed is defined
- node_update_needed

- name: Start PM2
ansible.builtin.include_role:
name: pm2
tasks_from: pm2-conf.yml
apply:
tags:
- nvm-install
- nvm
when:
- node_update_needed is defined
- node_update_needed
30 changes: 30 additions & 0 deletions roles/nvm/tasks/nvm-purge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@
name: daemon
tasks_from: daemon-stop.yml

- name: Purge Logrotate
ansible.builtin.include_role:
name: logrotate
tasks_from: logrotate-purge.yml
apply:
tags:
- nvm-purge
- purge
become: true

- name: Purge PM2
ansible.builtin.include_role:
name: pm2
tasks_from: pm2-purge.yml
apply:
tags:
- nvm-purge
- purge
become: true

- name: Purge Watchdog
ansible.builtin.include_role:
name: watchdog
tasks_from: watchdog-purge.yml
apply:
tags:
- nvm-purge
- purge
become: true

- name: Remove nvm and node files
ansible.builtin.file:
path: "{{ item }}"
Expand Down
1 change: 1 addition & 0 deletions roles/pm2/tasks/pm2-stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
source /home/{{ global.user }}/.nvm/nvm.sh
{{ item }}
changed_when: false
ignore_errors: true
args:
executable: /bin/bash
loop:
Expand Down

0 comments on commit 412d50a

Please sign in to comment.