|
1 | 1 | --- |
2 | | -- name: Create keyrings directory |
3 | | - ansible.builtin.file: |
4 | | - path: /etc/apt/keyrings |
5 | | - state: directory |
6 | | - mode: "0755" |
| 2 | +# On Debian >= 13, use native Node.js packages since the NodeSource GPG key |
| 3 | +# uses SHA-1, rejected by apt. See https://github.com/nodesource/distributions/issues/1908 |
| 4 | +# On older versions, use NodeSource to provide Node.js >= 20 as required by the engine. |
7 | 5 |
|
8 | | -- name: Download and import the Nodesource GPG key |
9 | | - ansible.builtin.shell: set -o pipefail && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg |
10 | | - args: |
11 | | - executable: /bin/bash |
| 6 | +- name: Install Node.js and NPM on Debian >= 13 |
| 7 | + when: ansible_distribution == 'Debian' and ansible_distribution_major_version | int >= 13 |
| 8 | + block: |
| 9 | + - name: Install Node.js and NPM |
| 10 | + ansible.builtin.apt: |
| 11 | + name: |
| 12 | + - nodejs |
| 13 | + - npm |
| 14 | + state: present |
| 15 | + update_cache: true |
12 | 16 |
|
13 | | -- name: Create deb repository |
14 | | - ansible.builtin.shell: set -o pipefail && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list # Remember to update the major version of NPM when updating the major version of Node |
15 | | - args: |
16 | | - executable: /bin/bash |
| 17 | + - name: Install NPM to latest version 10 |
| 18 | + ansible.builtin.command: npm install -g npm@10 |
17 | 19 |
|
18 | | -- name: Install NodeJS and NPM |
19 | | - ansible.builtin.apt: |
20 | | - name: nodejs |
21 | | - update_cache: true |
22 | | - state: latest # The major version of NodeJS is provided by the NodeSource repository defined in the task above |
| 20 | +- name: Install Node.js and NPM on Debian < 13 |
| 21 | + when: ansible_distribution != 'Debian' or ansible_distribution_major_version | int < 13 |
| 22 | + block: |
| 23 | + - name: Create keyrings directory |
| 24 | + ansible.builtin.file: |
| 25 | + path: /etc/apt/keyrings |
| 26 | + state: directory |
| 27 | + mode: "755" |
23 | 28 |
|
24 | | -- name: Update NPM to latest version 10 |
25 | | - ansible.builtin.command: npm install -g npm@10 |
| 29 | + - name: Download and import the NodeSource GPG key |
| 30 | + ansible.builtin.shell: set -o pipefail && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 31 | + args: |
| 32 | + executable: /bin/bash |
| 33 | + |
| 34 | + - name: Add NodeSource APT repository |
| 35 | + ansible.builtin.shell: set -o pipefail && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list # Remember to update the major version of NPM when updating the major version of Node |
| 36 | + args: |
| 37 | + executable: /bin/bash |
| 38 | + |
| 39 | + - name: Install Node.js |
| 40 | + ansible.builtin.apt: |
| 41 | + name: nodejs |
| 42 | + update_cache: true |
| 43 | + state: latest # The major version of NodeJS is provided by the NodeSource repository defined in the task above |
| 44 | + |
| 45 | + - name: Install NPM 10 |
| 46 | + ansible.builtin.command: npm install -g npm@10 |
0 commit comments