Adrià Vilanova Martínez | 166f67f | 2024-09-29 12:32:38 +0200 | [diff] [blame] | 1 | - name: Ensure we know what version of node to install |
| 2 | assert: |
| 3 | that: node_version is defined |
| 4 | |
Adrià Vilanova Martínez | 16b9f46 | 2024-05-04 01:08:33 +0200 | [diff] [blame] | 5 | - name: Update apt cache |
| 6 | apt: |
| 7 | update_cache: yes |
| 8 | become: yes |
| 9 | |
| 10 | - name: Install prereqs |
| 11 | package: |
| 12 | name: apt-transport-https |
| 13 | state: present |
| 14 | become: yes |
| 15 | |
| 16 | - name: Pin nodejs installs to nodesource |
| 17 | copy: |
| 18 | src: 00-nodesource.pref |
| 19 | dest: /etc/apt/preferences.d/00-nodesource.pref |
| 20 | mode: 0644 |
| 21 | become: yes |
| 22 | |
| 23 | - name: Add all repositories |
| 24 | include_role: |
| 25 | name: ensure-package-repositories |
| 26 | vars: |
| 27 | repositories_keys: |
Adrià Vilanova Martínez | 166f67f | 2024-09-29 12:32:38 +0200 | [diff] [blame] | 28 | - url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key |
| 29 | repositories_list: |
| 30 | - repo: deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main |
| 31 | - repo: deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main |
| 32 | when: node_version | int < 16 |
| 33 | |
| 34 | - name: Add all repositories |
| 35 | include_role: |
| 36 | name: ensure-package-repositories |
| 37 | vars: |
| 38 | repositories_keys: |
Adrià Vilanova Martínez | 16b9f46 | 2024-05-04 01:08:33 +0200 | [diff] [blame] | 39 | - url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key |
| 40 | repositories_list: |
Adrià Vilanova Martínez | 16b9f46 | 2024-05-04 01:08:33 +0200 | [diff] [blame] | 41 | - repo: deb https://deb.nodesource.com/node_{{ node_version }}.x nodistro main |
Adrià Vilanova Martínez | 166f67f | 2024-09-29 12:32:38 +0200 | [diff] [blame] | 42 | when: node_version | int >= 16 |
Adrià Vilanova Martínez | 16b9f46 | 2024-05-04 01:08:33 +0200 | [diff] [blame] | 43 | |
| 44 | # Use template so that we can easily update this in the future to be able to |
| 45 | # use a mirror location. |
| 46 | - name: Pin NodeJS to nodesource apt repository |
| 47 | become: yes |
| 48 | template: |
| 49 | dest: /etc/apt/preferences.d/nodejs.pref |
| 50 | group: root |
| 51 | mode: 0644 |
| 52 | owner: root |
| 53 | src: nodejs.pref.j2 |
| 54 | |
| 55 | - name: Install NodeJS from nodesource |
| 56 | package: |
| 57 | name: nodejs |
| 58 | state: latest |
| 59 | become: yes |
| 60 | tags: |
| 61 | # Ignore ANSIBLE0010: We really want latest version |
| 62 | - skip_ansible_lint |
| 63 | |
| 64 | - name: Output node version |
| 65 | command: node --version |
| 66 | |
| 67 | - name: Output npm version |
| 68 | command: npm --version |