From 44c55a34edd726015f18b689c9b0a4f727c9a89f Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:45:25 +0100 Subject: [PATCH] update dev-desktops to node 22 --- .../roles/dev-desktop/tasks/dependencies.yml | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/ansible/roles/dev-desktop/tasks/dependencies.yml b/ansible/roles/dev-desktop/tasks/dependencies.yml index 21853632e..aefb2c010 100644 --- a/ansible/roles/dev-desktop/tasks/dependencies.yml +++ b/ansible/roles/dev-desktop/tasks/dependencies.yml @@ -151,22 +151,43 @@ path: /tmp/rustup-init.sh state: absent -- name: Check if Node is installed - command: node --version +# Keep the required Node major version in a single place for reuse. +- name: Set desired Node major version + set_fact: + node_major_version: "22" + +# Verify that the installed Node matches the required major version. +# +# The `failed_when` condition specifies that the task should be considered failed +# if the return code (`rc`) of the command is not in the list [0, 1, 2]. +# Explanation of return codes: +# - 0: the version is installed +# - 1: the version is not installed but the command executed successfully +# - 2: there was an error executing the command +- name: Check if Node {{ node_major_version }} is installed + shell: "node --version | grep -qE '^v{{ node_major_version }}\\.'" + # store the result of the command in a variable called `node_version` register: node_version changed_when: false - failed_when: node_version.rc != 0 and node_version.rc != 2 + failed_when: node_version.rc not in [0, 1, 2] + +- name: Uninstall previous Node version + apt: + name: + - nodejs + state: absent + when: node_version.rc != 0 - name: Set up NodeSource repository shell: | - curl -fsSL https://deb.nodesource.com/setup_18.x | bash - - when: node_version.rc == 2 + curl -fsSL https://deb.nodesource.com/setup_{{ node_major_version }}.x | bash - + when: node_version.rc != 0 +# In NodeSource, the package `nodejs` provides both `node` and `npm` - name: Install Node apt: - name: + name: - nodejs - - npm state: present update_cache: yes