Skip to content

Commit e719212

Browse files
committed
Task to clean the environment
Signed-off-by: Jesus Paz <[email protected]>
1 parent f7f0405 commit e719212

File tree

13 files changed

+101
-91
lines changed

13 files changed

+101
-91
lines changed

Makefile

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,76 @@
11
# ansible-nodejs-role
22

3-
This is an Ansible role which adds the the NodeSource APT repository and installs Node.js.
3+
This is an Ansible role that adds the NodeSource APT repository and installs Node.js.
44

5-
Currently this role supports the following operating systems and releases.
5+
## Supported Operating Systems
66

7-
* **Ubuntu 14.04 LTS** (Trusty Tahr)
8-
* **Ubuntu 16.04 LTS** (Xenial Xerus)
7+
Currently, this role supports the following operating systems and releases:
8+
9+
- **Ubuntu 20.04 LTS** (Focal Fossa)
10+
- **Ubuntu 22.04 LTS** (Jammy Jellyfish)
11+
- **Ubuntu 24.04 LTS** (Noble Numbat)
12+
- **Debian 10** (Buster)
13+
- **Debian 11** (Bullseye)
14+
- **Debian 12** (Bookworm)
915

1016
## Usage
1117

12-
You can either:
18+
### Install and Run Locally
19+
20+
To install and test this role locally, run:
21+
22+
```sh
23+
ANSIBLE_ROLES_PATH=../ ansible-playbook playbook.yml --ask-become-pass
24+
```
25+
26+
````
27+
28+
### Install via Ansible Galaxy
1329
14-
* Install the playbook via Ansible Galaxy:
30+
You can install this role directly from Ansible Galaxy:
1531
16-
```text
17-
$ ansible-galaxy install nodesource.node
32+
```sh
33+
ansible-galaxy install nodesource.node
1834
```
1935
20-
* Install the using [requirements.yml via Ansible Galaxy](http://docs.ansible.com/ansible/galaxy.html#installing-multiple-roles-from-a-file):
36+
Alternatively, use a `requirements.yml` file:
2137
22-
```yml
38+
```yaml
2339
- src: https://github.com/nodesource/ansible-nodejs-role
2440
```
2541
26-
```text
27-
$ ansible-galaxy install -r requirements.txt
42+
Then install it using:
43+
44+
```sh
45+
ansible-galaxy install -r requirements.yml
2846
```
2947
30-
## Configure
48+
## Configuration
3149
32-
Then configure it as follows:
50+
Example playbook configuration:
3351
3452
```yaml
3553
- hosts: servers
3654
roles:
37-
- nodesource.node
55+
- nodesource.node
3856
```
3957
4058
## Role Variables
4159
4260
- `nodejs_nodesource_pin_priority`: Pin-Priority of the NodeSource repository (default: `500`).
43-
- `nodejs_version`: Set Node version (options: `0.10` or `0.12` or `4.6`, default: `4.6`)
61+
- `nodejs_version`: Set the Node.js version (options: `18.x`, `20.x`, `22.x`, `23.x`, default: `22.x`).
4462
4563
## Testing
4664
47-
To test this role using [molecule](https://github.com/metacloud/molecule):
48-
49-
```
50-
$ make
51-
$ molecule test
52-
```
65+
This role is automatically tested using GitHub Actions. To see how the CI/CD pipeline is configured, check the `.github/workflows/ci.yml` file.
5366
5467
## Author
5568
56-
Mark Wolfe <[email protected]>
69+
Originally developed by Mark Wolfe.
70+
Maintained by NodeSource.
5771
5872
## License
5973
60-
This code is Copyright (c) 2014 NodeSource and Mark Wolfe and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included [LICENSE.md](./LICENSE.md) file for more details.
74+
This code is licensed under the MIT License. See the included [LICENSE.md](./LICENSE.md) file for more details.
75+
76+
````

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ nodejs_supported_versions:
1010
- "18.x"
1111
- "20.x"
1212
- "22.x"
13+
- "23.x"

meta/main.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
galaxy_info:
33
author: NodeSource
44
namespace: nodesource
5-
role_name: ansible_nodejs_role
5+
role_name: ansible-nodejs-role
66
description: Installs the NodeSource Node.js binary packages
77
company: NodeSource
88
license: MIT
@@ -31,15 +31,15 @@ galaxy_info:
3131
- name: GenericLinux
3232
versions:
3333
- all
34-
categories:
35-
- development
36-
- networking
37-
- packaging
38-
- web
39-
- system
40-
- infrastructure
41-
- performance
42-
- security
43-
- databases
44-
- cloud
34+
categories:
35+
- development
36+
- networking
37+
- packaging
38+
- web
39+
- system
40+
- infrastructure
41+
- performance
42+
- security
43+
- databases
44+
- cloud
4545
dependencies: []

playbook.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
---
2-
- hosts: all
2+
- name: Install Node.js using ansible-nodejs-role
3+
hosts: localhost
4+
connection: local
5+
become: true
36
roles:
47
- role: ansible-nodejs-role
8+
vars:
9+
nodejs_version: "22.x"
10+
nodejs_nodesource_pin_priority: 600

role.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tasks/main.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,39 @@
2020
state: directory
2121
mode: "0755"
2222

23-
- name: Remove old NodeSource GPG key (if exists)
24-
ansible.builtin.file:
25-
path: /usr/share/keyrings/nodesource.gpg
23+
- name: Uninstall existing Node.js and clean dependencies
24+
ansible.builtin.apt:
25+
name: nodejs
2626
state: absent
27+
autoremove: yes
28+
register: node_uninstall
29+
changed_when: node_uninstall.changed
2730

28-
- name: Remove old NodeSource repository list (if exists)
31+
- name: Remove old NodeSource files (if exist)
2932
ansible.builtin.file:
30-
path: /etc/apt/sources.list.d/nodesource.list
33+
path: "{{ item }}"
3134
state: absent
35+
loop:
36+
- /usr/share/keyrings/nodesource.gpg
37+
- /etc/apt/sources.list.d/nodesource.list
38+
- /etc/apt/preferences.d/nodejs
3239

33-
- name: Download and import NodeSource GPG key
40+
- name: Download NodeSource GPG key
3441
ansible.builtin.get_url:
3542
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
36-
dest: /usr/share/keyrings/nodesource.gpg
43+
dest: /tmp/nodesource-repo.gpg
44+
mode: "0644"
45+
46+
- name: Convert GPG key to binary format and store in keyrings
47+
ansible.builtin.command:
48+
cmd: gpg --dearmor -o /usr/share/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg
49+
creates: /usr/share/keyrings/nodesource.gpg
50+
become: yes
51+
52+
- name: Set correct permissions for the GPG key
53+
ansible.builtin.file:
54+
path: /usr/share/keyrings/nodesource.gpg
3755
mode: "0644"
38-
register: gpg_download
39-
failed_when: gpg_download.failed
4056

4157
- name: Detect system architecture
4258
ansible.builtin.command: dpkg --print-architecture
@@ -69,3 +85,16 @@
6985
ansible.builtin.apt:
7086
pkg: nodejs
7187
state: present
88+
89+
- name: Verify Node.js installation
90+
ansible.builtin.command:
91+
cmd: node -v
92+
register: node_version_output
93+
changed_when: false
94+
95+
- name: Validate installed Node.js version
96+
ansible.builtin.assert:
97+
that:
98+
- "node_version_output.stdout is search(nodejs_version | regex_replace('x', ''))"
99+
success_msg: "Node.js is correctly installed with version {{ node_version_output.stdout }}"
100+
fail_msg: "Expected Node.js {{ nodejs_version }}, but found {{ node_version_output.stdout }}"

templates/etc/apt/preferences.d/deb_nodesource_com_node.pref.2

Lines changed: 0 additions & 5 deletions
This file was deleted.

templates/nodesource.list.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
deb [arch={{ system_arch.stdout }} signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main
1+
deb [arch={{ system_arch.stdout }} signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_{{ nodejs_version }} nodistro main

templates/preferences.d/nodejs.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Package: nodejs
22
Pin: origin deb.nodesource.com
3-
Pin-Priority: 600
3+
Pin-Priority: {{ nodejs_nodesource_pin_priority }}

0 commit comments

Comments
 (0)