diff --git a/.fixtures.yml b/.fixtures.yml index 4196f1e..aedf5da 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,3 +2,4 @@ fixtures: repositories: stdlib: https://github.com/puppetlabs/puppetlabs-stdlib + alternatives: https://github.com/voxpupuli/puppet-alternatives diff --git a/REFERENCE.md b/REFERENCE.md index 4808be2..78571d2 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -7,6 +7,7 @@ ### Classes * [`example`](#example): An example class +* [`example::profile_java`](#example--profile_java) ## Classes @@ -37,3 +38,19 @@ The content in the file Default value: `'Hello World!'` +### `example::profile_java` + +The example::profile_java class. + +#### Parameters + +The following parameters are available in the `example::profile_java` class: + +* [`version`](#-example--profile_java--version) + +##### `version` + +Data type: `Enum['8', '11', '17', '21']` + + + diff --git a/manifests/profile_java.pp b/manifests/profile_java.pp new file mode 100644 index 0000000..36792f3 --- /dev/null +++ b/manifests/profile_java.pp @@ -0,0 +1,17 @@ +class example::profile_java ( + Enum['8', '11', '17', '21'] $version, +) { + $_version = $version ? { + '8' => '1.8.0', + default => $version, + } + package { 'java': + ensure => present, + name => "java-${_version}-openjdk", + } + + alternatives { 'java': + path => "java-${_version}-openjdk.${facts['os']['architecture']}", + require => Package['java'], + } +} diff --git a/metadata.json b/metadata.json index 88ba7b9..8e2b792 100644 --- a/metadata.json +++ b/metadata.json @@ -25,23 +25,12 @@ "9" ] }, - { - "operatingsystem": "Archlinux" - }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "9" ] }, - { - "operatingsystem": "Debian", - "operatingsystemrelease": [ - "11", - "12", - "13" - ] - }, { "operatingsystem": "Fedora", "operatingsystemrelease": [ @@ -68,14 +57,6 @@ "8", "9" ] - }, - { - "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ - "20.04", - "22.04", - "24.04" - ] } ] } diff --git a/spec/classes/profile_spec.rb b/spec/classes/profile_spec.rb new file mode 100644 index 0000000..b6a606a --- /dev/null +++ b/spec/classes/profile_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'example::profile_java' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + let(:params) do + { 'version' => '11' } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_package('java').with(name: 'java-11-openjdk-headless', ensure: 'present') } + it { is_expected.to contain_alternatives('java').with(path: 'java-11-openjdk.x86_64') } + it { is_expected.to contain_alternatives('java').that_requires('Package[java]') } + end + end +end