Skip to content

Commit

Permalink
Task to clean the environment
Browse files Browse the repository at this point in the history
Signed-off-by: Jesus Paz <jeherpabo@gmail.com>
  • Loading branch information
JesusPaz committed Feb 7, 2025
1 parent 23d3321 commit 803ebb6
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 91 deletions.
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,76 @@
# ansible-nodejs-role

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

Currently this role supports the following operating systems and releases.
## Supported Operating Systems

* **Ubuntu 14.04 LTS** (Trusty Tahr)
* **Ubuntu 16.04 LTS** (Xenial Xerus)
Currently, this role supports the following operating systems and releases:

- **Ubuntu 20.04 LTS** (Focal Fossa)
- **Ubuntu 22.04 LTS** (Jammy Jellyfish)
- **Ubuntu 24.04 LTS** (Noble Numbat)
- **Debian 10** (Buster)
- **Debian 11** (Bullseye)
- **Debian 12** (Bookworm)

## Usage

You can either:
### Install and Run Locally

To install and test this role locally, run:

```sh
ANSIBLE_ROLES_PATH=../ ansible-playbook playbook.yml --ask-become-pass
```

````
### Install via Ansible Galaxy
* Install the playbook via Ansible Galaxy:
You can install this role directly from Ansible Galaxy:
```text
$ ansible-galaxy install nodesource.node
```sh
ansible-galaxy install nodesource.node
```
* Install the using [requirements.yml via Ansible Galaxy](http://docs.ansible.com/ansible/galaxy.html#installing-multiple-roles-from-a-file):
Alternatively, use a `requirements.yml` file:
```yml
```yaml
- src: https://github.com/nodesource/ansible-nodejs-role
```
```text
$ ansible-galaxy install -r requirements.txt
Then install it using:
```sh
ansible-galaxy install -r requirements.yml
```
## Configure
## Configuration
Then configure it as follows:
Example playbook configuration:
```yaml
- hosts: servers
roles:
- nodesource.node
- nodesource.node
```
## Role Variables
- `nodejs_nodesource_pin_priority`: Pin-Priority of the NodeSource repository (default: `500`).
- `nodejs_version`: Set Node version (options: `0.10` or `0.12` or `4.6`, default: `4.6`)
- `nodejs_version`: Set the Node.js version (options: `18.x`, `20.x`, `22.x`, `23.x`, default: `22.x`).
## Testing
To test this role using [molecule](https://github.com/metacloud/molecule):

```
$ make
$ molecule test
```
This role is automatically tested using GitHub Actions. To see how the CI/CD pipeline is configured, check the `.github/workflows/ci.yml` file.
## Author
Mark Wolfe <mark@wolfe.id.au>
Originally developed by Mark Wolfe.
Maintained by NodeSource.
## License
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.
This code is licensed under the MIT License. See the included [LICENSE.md](./LICENSE.md) file for more details.
````
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ nodejs_supported_versions:
- "18.x"
- "20.x"
- "22.x"
- "23.x"
24 changes: 12 additions & 12 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
galaxy_info:
author: NodeSource
namespace: nodesource
role_name: ansible_nodejs_role
role_name: ansible-nodejs-role
description: Installs the NodeSource Node.js binary packages
company: NodeSource
license: MIT
Expand Down Expand Up @@ -31,15 +31,15 @@ galaxy_info:
- name: GenericLinux
versions:
- all
categories:
- development
- networking
- packaging
- web
- system
- infrastructure
- performance
- security
- databases
- cloud
categories:
- development
- networking
- packaging
- web
- system
- infrastructure
- performance
- security
- databases
- cloud
dependencies: []
8 changes: 7 additions & 1 deletion playbook.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- hosts: all
- name: Install Node.js using ansible-nodejs-role
hosts: localhost
connection: local
become: true
roles:
- role: ansible-nodejs-role
vars:
nodejs_version: "22.x"
nodejs_nodesource_pin_priority: 600
9 changes: 0 additions & 9 deletions role.yml

This file was deleted.

47 changes: 38 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,39 @@
state: directory
mode: "0755"

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

- name: Remove old NodeSource repository list (if exists)
- name: Remove old NodeSource files (if exist)
ansible.builtin.file:
path: /etc/apt/sources.list.d/nodesource.list
path: "{{ item }}"
state: absent
loop:
- /usr/share/keyrings/nodesource.gpg
- /etc/apt/sources.list.d/nodesource.list
- /etc/apt/preferences.d/nodejs

- name: Download and import NodeSource GPG key
- name: Download NodeSource GPG key
ansible.builtin.get_url:
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
dest: /usr/share/keyrings/nodesource.gpg
dest: /tmp/nodesource-repo.gpg
mode: "0644"

- name: Convert GPG key to binary format and store in keyrings
ansible.builtin.command:
cmd: gpg --dearmor -o /usr/share/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg
creates: /usr/share/keyrings/nodesource.gpg
become: yes

- name: Set correct permissions for the GPG key
ansible.builtin.file:
path: /usr/share/keyrings/nodesource.gpg
mode: "0644"
register: gpg_download
failed_when: gpg_download.failed

- name: Detect system architecture
ansible.builtin.command: dpkg --print-architecture
Expand Down Expand Up @@ -69,3 +85,16 @@
ansible.builtin.apt:
pkg: nodejs
state: present

- name: Verify Node.js installation
ansible.builtin.command:
cmd: node -v
register: node_version_output
changed_when: false

- name: Validate installed Node.js version
ansible.builtin.assert:
that:
- "node_version_output.stdout is search(nodejs_version | regex_replace('x', ''))"
success_msg: "Node.js is correctly installed with version {{ node_version_output.stdout }}"
fail_msg: "Expected Node.js {{ nodejs_version }}, but found {{ node_version_output.stdout }}"

This file was deleted.

2 changes: 1 addition & 1 deletion templates/nodesource.list.j2
Original file line number Diff line number Diff line change
@@ -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
deb [arch={{ system_arch.stdout }} signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_{{ nodejs_version }} nodistro main
2 changes: 1 addition & 1 deletion templates/preferences.d/nodejs.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Package: nodejs
Pin: origin deb.nodesource.com
Pin-Priority: 600
Pin-Priority: {{ nodejs_nodesource_pin_priority }}
2 changes: 0 additions & 2 deletions tests/localhosts

This file was deleted.

12 changes: 0 additions & 12 deletions tests/test_default.py

This file was deleted.

3 changes: 1 addition & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
# Node.js version (override if needed)
nodejs_version: "22.x"
# vars file for nodejs

0 comments on commit 803ebb6

Please sign in to comment.