Skip to content

Commit

Permalink
Support new distributions scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusPaz committed Feb 6, 2025
1 parent cbbbfe1 commit 23d3321
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 119 deletions.
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)
=====================

Copyright (c) 2014 NodeSource and Mark Wolfe
Copyright (c) 2025 NodeSource
--------------------------------------------

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand Down
12 changes: 9 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
# Default Node.js version (can be overridden)
nodejs_version: "22.x"

# Pin-Priority of NodeSource repository
nodejs_nodesource_pin_priority: 500
nodejs_nodesource_pin_priority: 600

# 0.10 or 0.12 or 4.x
nodejs_version: "4.6"
# List of supported Node.js versions
nodejs_supported_versions:
- "18.x"
- "20.x"
- "22.x"
49 changes: 38 additions & 11 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
---
galaxy_info:
author: Mark Wolfe
author: NodeSource
namespace: nodesource
role_name: ansible_nodejs_role
description: Installs the NodeSource Node.js binary packages
company: NodeSource
license: MIT
min_ansible_version: 1.2
min_ansible_version: "2.16"
platforms:
- name: Ubuntu
versions:
- precise
- trusty
categories:
- development
- networking
- packaging
- web
- name: Ubuntu
versions:
- focal
- jammy
- noble
- name: Debian
versions:
- buster
- bullseye
- bookworm
- name: EL
versions:
- "8"
- "9"
- "10"
- name: Fedora
versions:
- "39"
- "40"
- "41"
- name: GenericLinux
versions:
- all
categories:
- development
- networking
- packaging
- web
- system
- infrastructure
- performance
- security
- databases
- cloud
dependencies: []
22 changes: 0 additions & 22 deletions molecule.yml

This file was deleted.

4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
ansible==2.1
testinfra==1.3.0
molecule
ansible==11.2.0
9 changes: 5 additions & 4 deletions role.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
- name: Test the Node.js role
hosts: all
- name: Install Node.js using ansible-nodejs-role
hosts: localhost
connection: local
become: yes
roles:
- role: "ansible-nodejs-role"
- role: ansible-nodejs-role
vars:
nodejs_version: '4'
nodejs_version: "18.x"
102 changes: 64 additions & 38 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,71 @@
# Install Node.js using packages crafted by NodeSource
---
- name: Ensure the system can use the HTTPS transport for APT
stat:
path: /usr/lib/apt/methods/https
register: apt_https_transport

- name: Install HTTPS transport for APT
apt:
pkg: apt-transport-https
state: installed
when: not apt_https_transport.stat.exists

- name: Install GPG
apt:
pkg: gnupg
state: installed

- name: Import the NodeSource GPG key into apt
apt_key:
url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
id: "68576280"
state: present
- name: Ensure selected Node.js version is valid
ansible.builtin.assert:
that:
- nodejs_version in nodejs_supported_versions
fail_msg: "Invalid Node.js version: {{ nodejs_version }}. Supported versions: {{ nodejs_supported_versions | join(', ') }}."

- name: Add NodeSource deb repository
apt_repository:
repo: 'deb https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
- name: Ensure required packages are installed
ansible.builtin.apt:
pkg:
- ca-certificates
- curl
- gnupg
state: present
update_cache: yes

- name: Add NodeSource deb-src repository
apt_repository:
repo: 'deb-src https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
state: present
- name: Ensure /usr/share/keyrings directory exists
ansible.builtin.file:
path: /usr/share/keyrings
state: directory
mode: "0755"

- name: Add NodeSource repository preferences
template:
src: etc/apt/preferences.d/deb_nodesource_com_node.pref.2
dest: /etc/apt/preferences.d/deb_nodesource_com_node.pref
- name: Remove old NodeSource GPG key (if exists)
ansible.builtin.file:
path: /usr/share/keyrings/nodesource.gpg
state: absent

- name: Install Node.js
apt:
pkg:
- nodejs
state: installed
- name: Remove old NodeSource repository list (if exists)
ansible.builtin.file:
path: /etc/apt/sources.list.d/nodesource.list
state: absent

- name: Download and import NodeSource GPG key
ansible.builtin.get_url:
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
dest: /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
register: system_arch
changed_when: false

- name: Ensure architecture is supported
ansible.builtin.assert:
that:
- system_arch.stdout in ['amd64', 'arm64', 'armhf']
fail_msg: "Unsupported architecture: {{ system_arch.stdout }}. Only amd64, arm64, and armhf are supported."

- name: Add NodeSource APT repository
ansible.builtin.template:
src: nodesource.list.j2
dest: /etc/apt/sources.list.d/nodesource.list
mode: "0644"

- name: Add package pinning for Node.js
ansible.builtin.template:
src: preferences.d/nodejs.j2
dest: /etc/apt/preferences.d/nodejs
mode: "0644"

- name: Update APT cache
ansible.builtin.apt:
update_cache: yes

- name: Install Node.js
ansible.builtin.apt:
pkg: nodejs
state: present
1 change: 1 addition & 0 deletions templates/nodesource.list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb [arch={{ system_arch.stdout }} signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main
3 changes: 3 additions & 0 deletions templates/preferences.d/nodejs.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Package: nodejs
Pin: origin deb.nodesource.com
Pin-Priority: 600
4 changes: 2 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
# vars file for nodejs
debian_repo_version: "{{ nodejs_version if '4' not in nodejs_version else '4.x' }}"
# Node.js version (override if needed)
nodejs_version: "22.x"

0 comments on commit 23d3321

Please sign in to comment.