diff --git a/README.md b/README.md index 12c78321..b23f643d 100644 --- a/README.md +++ b/README.md @@ -369,7 +369,7 @@ See [`metadata.json`](metadata.json) for supported operating systems. This modules uses `puppetlabs-apt` for the management of the NodeSource repository. If using an operating system of the Debian-based family, you will -need to ensure that `puppetlabs-apt` version 4.4.0 or above is installed. +need to ensure that `puppetlabs-apt` version 10.0.0 or above is installed. If using CentOS/RHEL and you wish to install Node.js from EPEL rather than from the NodeSource repository, you will need to ensure `puppet-epel` is diff --git a/manifests/params.pp b/manifests/params.pp index 971cdbaa..a824f945 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,7 +5,10 @@ $nodejs_package_ensure = 'installed' $repo_ensure = 'present' $repo_pin = undef - $repo_priority = 'absent' + $repo_priority = $facts['os']['family'] == 'Debian' ? { + true => '990', + default => 'absent', + } $repo_proxy = 'absent' $repo_proxy_password = 'absent' $repo_proxy_username = 'absent' diff --git a/manifests/repo/nodesource/apt.pp b/manifests/repo/nodesource/apt.pp index e3ba5358..d4998d7d 100644 --- a/manifests/repo/nodesource/apt.pp +++ b/manifests/repo/nodesource/apt.pp @@ -1,21 +1,30 @@ # PRIVATE CLASS: Do not use directly. class nodejs::repo::nodesource::apt { $ensure = $nodejs::repo::nodesource::ensure - $pin = $nodejs::repo::nodesource::pin + $priority = $nodejs::repo::nodesource::priority $url_suffix = $nodejs::repo::nodesource::url_suffix include apt if ($ensure != 'absent') { + apt::keyring { 'nodesource': + source => 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key', + filename => 'nodesource-repo.gpg.key.asc', + } + apt::source { 'nodesource': - key => { - 'name' => 'nodesource-repo.gpg.key.asc', - 'source' => 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key', - }, - location => "https://deb.nodesource.com/node_${url_suffix}", - pin => $pin, - release => 'nodistro', - repos => 'main', + source_format => 'sources', + location => ["https://deb.nodesource.com/node_${url_suffix}",], + keyring => '/etc/apt/keyrings/nodesource-repo.gpg.key.asc', + release => ['nodistro',], + repos => ['main',], + types => ['deb',], + require => Apt::Keyring['nodesource'], + } + + apt::pin { 'nodesource': + origin => 'deb.nodesource.com', + priority => $priority, } Apt::Source['nodesource'] -> Package<| tag == 'nodesource_repo' |> @@ -26,5 +35,17 @@ apt::source { 'nodesource': ensure => 'absent', } + # Workaround https://github.com/puppetlabs/puppetlabs-apt/issues/1245 + file { '/etc/apt/sources.list.d/nodesource.sources': + ensure => 'absent', + notify => Class['Apt::Update'], + } + apt::pin { 'nodesource': + ensure => 'absent', + } + apt::keyring { 'nodesource': + ensure => 'absent', + filename => 'nodesource-repo.gpg.key.asc', + } } } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 818f15c5..89f3a2d8 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -40,21 +40,11 @@ def nodesource_unsupported(nodejs_version) include_examples 'cleanup' - # Debian 12 contains NodeJS 18, when we test 16 and 18, we need to force the nodesource version - # as Debians versions *can* be newer - repo_pin = - if %w[16 18].include?(nodejs_version) && fact('os.family') == 'Debian' && %w[12 13].include?(fact('os.release.major')) - '1000' - else - 'undef' - end - it_behaves_like 'an idempotent resource' do let(:manifest) do <<-PUPPET class { 'nodejs': repo_version => '#{nodejs_version}', - repo_pin => #{repo_pin}, } PUPPET end diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index f63b30db..c3104035 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -84,23 +84,23 @@ end end - context 'and repo_pin set to 10' do + context 'and repo_priority set to 10' do let :params do - default_params.merge!(repo_pin: '10') + default_params.merge!(repo_priority: '10') end - it 'the repo apt::source resource should contain pin = 10' do - is_expected.to contain_apt__source('nodesource').with('pin' => '10') + it 'the repo apt::source resource should contain priority = 10' do + is_expected.to contain_apt__pin('nodesource').with('priority' => '10') end end - context 'and repo_pin not set' do + context 'and repo_priority not set' do let :params do - default_params.merge!(repo_pin: :undef) + default_params.merge!(repo_priority: :undef) end - it 'the repo apt::source resource should contain pin = undef' do - is_expected.to contain_apt__source('nodesource').with('pin' => nil) + it 'the repo apt::source resource should contain priority = 990' do + is_expected.to contain_apt__pin('nodesource').with('priority' => 990) end end @@ -109,8 +109,8 @@ default_params.merge!(repo_version: '9') end - it 'the repo apt::source resource should contain location = https://deb.nodesource.com/node_9.x' do - is_expected.to contain_apt__source('nodesource').with('location' => 'https://deb.nodesource.com/node_9.x') + it 'the repo apt::source resource should contain location = [https://deb.nodesource.com/node_9.x]' do + is_expected.to contain_apt__source('nodesource').with('location' => ['https://deb.nodesource.com/node_9.x']) end end