From f00183055324103b6f170fe4f39fb43c45e796e0 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Fri, 14 Sep 2018 13:23:09 -0400 Subject: [PATCH 01/13] Existing Test Ruby Tweaks Rubocop wanted the addition of a few trailing commas on the tests as they currently exist. Adding these here ensures that they don't clutter my direct changes. --- .rspec | 2 +- spec/classes/init_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.rspec b/.rspec index 8c18f1a..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 01eb7f0..67c8b3b 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -14,7 +14,7 @@ let :params do { rh_password: 'password', - rh_user: 'username' + rh_user: 'username', } end @@ -24,13 +24,13 @@ it { is_expected.to contain_exec('sm yum clean all') } it do is_expected.to contain_exec('RHSM-register').with( - command: "subscription-manager register --name='#{facts[:fqdn]}' --username='username' --password='password'" + command: "subscription-manager register --name='#{facts[:fqdn]}' --username='username' --password='password'", ) end it do is_expected.to contain_exec('RHSM-subscribe').with( - command: 'subscription-manager attach --auto' + command: 'subscription-manager attach --auto', ) end end @@ -39,13 +39,13 @@ let :params do { org: 'org', - activationkey: 'key' + activationkey: 'key', } end it do is_expected.to contain_exec('RHSM-register').with( - command: "subscription-manager register --name='#{facts[:fqdn]}' --org='org' --activationkey='key'" + command: "subscription-manager register --name='#{facts[:fqdn]}' --org='org' --activationkey='key'", ) end end From 117d5a871e24bc5eba322b64ec6f336b79e68ab2 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 13:29:28 -0400 Subject: [PATCH 02/13] Subscription Manager - Repo Enable This commit reworks the main class to accept an array of repo IDs instead of the original boolean values. Each ID is used as the namevar of a repo define entity which uses the `subscription-manager repos --enable` command to activate. --- lib/facter/rhsm.rb | 24 ++++++++++++ lib/facter/rhsm_repos.rb | 11 ------ lib/facter/rhsm_subscription_type.rb | 12 ------ manifests/init.pp | 23 +++++------- manifests/repo.pp | 10 +++-- spec/classes/init_spec.rb | 24 +++++++++++- spec/default_facts.yml | 10 +---- spec/defines/repo_spec.rb | 56 ++++++++++++++++++++++++++++ 8 files changed, 121 insertions(+), 49 deletions(-) create mode 100644 lib/facter/rhsm.rb delete mode 100644 lib/facter/rhsm_repos.rb delete mode 100644 lib/facter/rhsm_subscription_type.rb create mode 100644 spec/defines/repo_spec.rb diff --git a/lib/facter/rhsm.rb b/lib/facter/rhsm.rb new file mode 100644 index 0000000..00d528f --- /dev/null +++ b/lib/facter/rhsm.rb @@ -0,0 +1,24 @@ +Facter.add(:rhsm, type: :aggregate) do + confine Facter.value(:os)['name'] => 'RedHat' + + # List the currently enabled repositories + chunk(:enabled_repo_ids) do + repos = Array.[] + repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") + repo_list.each_line do |line| + repos.push(line.strip) + end + repos + end + + # Determine the subscription type + chunk(:subscription_type) do + if File.exist? '/etc/sysconfig/rhn/systemid' + 'rhn_classic' + elsif File.exist? '/etc/pki/consumer/cert.pem' + 'rhsm' + else + 'unknown' + end + end +end diff --git a/lib/facter/rhsm_repos.rb b/lib/facter/rhsm_repos.rb deleted file mode 100644 index 25f1791..0000000 --- a/lib/facter/rhsm_repos.rb +++ /dev/null @@ -1,11 +0,0 @@ -Facter.add('rhsm_repos') do - confine osfamily: :RedHat - setcode do - repos = Array.[] - repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") - repo_list.each_line do |line| - repos.push(line.strip) - end - repos - end -end diff --git a/lib/facter/rhsm_subscription_type.rb b/lib/facter/rhsm_subscription_type.rb deleted file mode 100644 index f7e98b5..0000000 --- a/lib/facter/rhsm_subscription_type.rb +++ /dev/null @@ -1,12 +0,0 @@ -Facter.add('rhsm_subscription_type') do - confine osfamily: :RedHat - setcode do - if File.exist? '/etc/sysconfig/rhn/systemid' - 'rhn_classic' - elsif File.exist? '/etc/pki/consumer/cert.pem' - 'rhsm' - else - 'unknown' - end - end -end diff --git a/manifests/init.pp b/manifests/init.pp index 5b92f1a..9bddf1a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -40,7 +40,10 @@ # @param package_ensure [String] Whether to install subscription-manager # @param repo_extras [Boolean] Enable extras repository # @param repo_optional [Boolean] Enable optional repository -# +# @param enabled_repo_ids [Array[String] +# A listing of the Repo IDs to provide to the subscription-manager repo +# --enable command. +# # @example # include rhsm # @@ -72,8 +75,7 @@ $manage_repos = 1, $full_refresh_on_yum = 0, $package_ensure = 'latest', - $repo_extras = false, - $repo_optional = false + Optional[Array[String]] $enabled_repo_ids = [], ) { if ($rh_user == undef and $rh_password == undef) and ($org == undef and $activationkey == undef) { @@ -157,16 +159,11 @@ require => Exec['RHSM-register'], } - if $repo_extras { - ::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-extras-rpms": - require => Exec['RHSM-register'], + unless(empty($enabled_repo_ids)) { + $enabled_repo_ids.each | $repo_id | { + ::rhsm::repo { $repo_id: + require => Exec['RHSM-subscribe'], + } } } - - if $repo_optional { - ::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-optional-rpms": - require => Exec['RHSM-register'], - } - } - } diff --git a/manifests/repo.pp b/manifests/repo.pp index 9bbf85f..1f54c01 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -12,9 +12,11 @@ # ::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-extras-rpms": } define rhsm::repo ( ) { - yumrepo { $title: - enabled => '1', - require => Package['subscription-manager'], - target => '/etc/yum.repos.d/redhat.repo', + # Check to see if the title is an enabled repo + if ! ($title in $facts['rhsm']['enabled_repo_ids']) { + exec { "RHSM-enable_${title}": + command => "subscription-manager repos --enable ${title}", + path => '/bin:/usr/bin:/usr/sbin', + } } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 67c8b3b..6129bea 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -3,7 +3,11 @@ on_supported_os.each do |os, facts| context "on supported OS #{os} " do let :facts do - facts + facts.merge( + 'rhsm' => { + 'enabled_repo_ids' => [], + }, + ) end context 'with defaults for all parameters' do @@ -49,6 +53,24 @@ ) end end + + context 'with list of repos to enable' do + let(:params) do + { + rh_password: 'password', + rh_user: 'username', + enabled_repo_ids: [ + 'rhel-7-server-rpms', + 'rhel-7-server-optional-rpms', + ], + } + end + + it { is_expected.to have_rhsm__repo_resource_count(2) } + + it { is_expected.to contain_rhsm__repo('rhel-7-server-rpms').that_requires('Exec[RHSM-subscribe]') } + it { is_expected.to contain_rhsm__repo('rhel-7-server-optional-rpms').that_requires('Exec[RHSM-subscribe]') } + end end end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 13c4165..3248be5 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -1,12 +1,6 @@ -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config +# Use default_module_facts.yml for module specific facts. # -# use default_module_facts.yaml for module specific -# facts. -# -# Hint if using with rspec-puppet-facts ("on_supported_os.each"): -# if a same named fact exists in facterdb it will be overridden. +# Facts specified here will override the values provided by rspec-puppet-facts. --- concat_basedir: "/tmp" ipaddress: "172.16.254.254" diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb new file mode 100644 index 0000000..5cf85ab --- /dev/null +++ b/spec/defines/repo_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' +describe 'rhsm::repo' do + on_supported_os.each do |os, facts| + context "on supported OS #{os} " do + let(:facts) do + facts.merge( + 'rhsm' => { + 'enabled_repo_ids' => [], + }, + ) + end + + context 'enabling server rpms' do + let(:title) { 'rhel-7-server-rpms' } + + it { is_expected.to compile } + + it { + is_expected.to contain_exec('RHSM-enable_rhel-7-server-rpms').with( + command: 'subscription-manager repos --enable rhel-7-server-rpms', + ) + } + end + + context 'enabling optional rpms' do + let(:title) { 'rhel-7-optional-rpms' } + + it { is_expected.to compile } + + it { + is_expected.to contain_exec('RHSM-enable_rhel-7-optional-rpms').with( + command: 'subscription-manager repos --enable rhel-7-optional-rpms', + ) + } + end + + context 'skipping already enabled repo' do + let(:title) { 'rhel-7-optional-rpms' } + + let(:facts) do + facts.merge( + 'rhsm' => { + 'enabled_repo_ids' => [ + 'rhel-7-optional-rpms', + ], + }, + ) + end + + it { is_expected.to compile } + + it { is_expected.not_to contain_exec('RHSM-enable_rhel-7-optional-rpms') } + end + end + end +end From c56da589a24f3b9b938d07b84cd704ba59dc9db5 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 14:07:44 -0400 Subject: [PATCH 03/13] Handle Undefined Repo List This commit corrects a bug where an undefined repo list would cause the manifest to fail during compilation. --- data/common.yaml | 3 +++ hiera.yaml | 12 ++++++++++++ manifests/repo.pp | 10 ++++++---- spec/classes/init_spec.rb | 6 +----- 4 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 data/common.yaml create mode 100644 hiera.yaml diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..5611ebb --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,3 @@ +--- +# Define an empty array so we don't error +rhsm::enabled_repo_ids: diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..7d5f450 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,12 @@ +--- +version: 5 +defaults: + # The default value for "datadir" is "data" under the same directory as the hiera.yaml + # file (this file) + # When specifying a datadir, make sure the directory exists. + # See https://docs.puppet.com/puppet/latest/environments.html for further details on environments. + datadir: data + data_hash: yaml_data +hierarchy: + - name: "Common Data" + path: 'common.yaml' diff --git a/manifests/repo.pp b/manifests/repo.pp index 1f54c01..656d457 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -13,10 +13,12 @@ define rhsm::repo ( ) { # Check to see if the title is an enabled repo - if ! ($title in $facts['rhsm']['enabled_repo_ids']) { - exec { "RHSM-enable_${title}": - command => "subscription-manager repos --enable ${title}", - path => '/bin:/usr/bin:/usr/sbin', + unless(empty($facts['rhsm'])) { + if ! ($title in $facts['rhsm']['enabled_repo_ids']) { + exec { "RHSM-enable_${title}": + command => "subscription-manager repos --enable ${title}", + path => '/bin:/usr/bin:/usr/sbin', + } } } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 6129bea..99b90f6 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -3,11 +3,7 @@ on_supported_os.each do |os, facts| context "on supported OS #{os} " do let :facts do - facts.merge( - 'rhsm' => { - 'enabled_repo_ids' => [], - }, - ) + facts end context 'with defaults for all parameters' do From ee274b27022c2825f8fef9928c6cb041386f802f Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 14:21:00 -0400 Subject: [PATCH 04/13] RHSM Composit Fact Structure Corrected the os/family filter so that it works. For some reason the Facter.value syntax wasn't actually finding the structured ['os']['name'] fact so I had to convert to a ruby block. Additionally, the aggregation wasn't correct as the return values from each chunk were not hashes and therefore couldn't be merged. --- lib/facter/rhsm.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/facter/rhsm.rb b/lib/facter/rhsm.rb index 00d528f..1e3e31f 100644 --- a/lib/facter/rhsm.rb +++ b/lib/facter/rhsm.rb @@ -1,5 +1,7 @@ Facter.add(:rhsm, type: :aggregate) do - confine Facter.value(:os)['name'] => 'RedHat' + confine :os do |os| + os['name'] == 'RedHat' + end # List the currently enabled repositories chunk(:enabled_repo_ids) do @@ -8,17 +10,17 @@ repo_list.each_line do |line| repos.push(line.strip) end - repos + { enabled_repo_ids: repos } end # Determine the subscription type chunk(:subscription_type) do if File.exist? '/etc/sysconfig/rhn/systemid' - 'rhn_classic' + { subscription_type: 'rhn_classic' } elsif File.exist? '/etc/pki/consumer/cert.pem' - 'rhsm' + { subscription_type: 'rhsm' } else - 'unknown' + { subscription_type: 'unknown' } end end end From b544d1df41a345e3aa6bdb6a482133f01367770a Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 15:05:28 -0400 Subject: [PATCH 05/13] Documentation Update Added the new parameter to both the README and the puppet strings. Also generated a new REFERENCE.md file using the puppetstring function. --- README.md | 27 ++++++ REFERENCE.md | 237 ++++++++++++++++++++++++++++++++++++++++++++++ manifests/init.pp | 2 - 3 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 REFERENCE.md diff --git a/README.md b/README.md index 5225cad..66cfd8f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,33 @@ You shouldn't specify the protocol, subscription-manager will use HTTP. For prox The proxy settings will be used to register the system and as connection option for all the YUM repositories generated in `/etc/yum.repos.d/redhat.repo` +### Enabled Repos + +A string array of repo IDs can now be provided as an argument to the class definition. This list will be used to enable the target repos if that has not already occurred. + +The following example enables the server and optional RPMs: + +```puppet +class { 'rhsm': + rh_user => 'myuser', + rh_password => 'mypassword', + enabled_repo_ids => [ + 'rhel-7-server-rpms', + 'rhel-7-server-optional-rpms' + ] +} +``` + +Alternatively, hiera can be utilized to specify these arguments. + +```yaml +rhsm::rh_user: myuser +rhsm::rh_password: mypassword +rhsm::enabled_repo_ids: + - 'rhel-7-server-rpms', + - 'rhel-7-server-optional-rpms' +``` + ### Satellite 6 Registering with Red Hat Satellite 6 needs some additional settings. diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..a4894b3 --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,237 @@ +# Reference + + +## Table of Contents + +**Classes** + +* [`rhsm`](#rhsm): Subscribe the node to RHSM + +**Defined types** + +* [`rhsm::repo`](#rhsmrepo): Manage additional RedHat repositories + +## Classes + +### rhsm + +rhsm + +Subscribe the node to RHSM + +Copyright 2014 Ger Apeldoorn, unless otherwise noted. + +#### Examples + +##### + +```puppet +include rhsm +``` + +##### + +```puppet +# Hierafile: +--- +rhsm::rh_user: myuser +rhsm::rh_password: mypassword +``` + +#### Parameters + +The following parameters are available in the `rhsm` class. + +##### `rh_user` + +Data type: `String` + +User for the Customer Portal. +You need to specify either (rh_user and rh_password) or (org and activationkey) + +Default value: `undef` + +##### `rh_password` + +Data type: `String` + +Password for the rh_user account + +Default value: `undef` + +##### `org` + +Data type: `String` + +Organization to use + +Default value: `undef` + +##### `activationkey` + +Data type: `String` + +Activationkey to use + +Default value: `undef` + +##### `servername` + +Data type: `String` + +Servername, default provided +Used directly in rhsm.conf template + +Default value: 'subscription.rhsm.redhat.com' + +##### `serverprefix` + +Data type: `String` + +server.prefix to use +Used directly in rhsm.conf template +/rhsm for Satellite 6 +/subscription for RHSM + +Default value: '/subscription' + +##### `serverport` + +Data type: `Integer` + +server.port to use +Used directly in rhsm.conf template + +Default value: 443 + +##### `ca_cert_dir` + +Data type: `String` + +Server CA certificate location + +Default value: '/etc/rhsm/ca/' + +##### `repo_ca_cert_filename` + +Data type: `String` + +File containting the CA cert to use when generating yum repo configs +katello-server-ca.pem for Satellite 6 +redhat-uep.pem for RHSM + +Default value: 'redhat-uep.pem' + +##### `repo_ca_cert_source` + +Data type: `String` + +URI, if set the content is used for CA file resource ${ca_cert_dir}/${repo_ca_cert_filename} +Possible values are puppet:, file: and http: + +Default value: `undef` + +##### `manage_repos` + +Data type: `Integer` + +1 if subscription manager should manage yum repos file or +0 if the subscription is only used for tracking purposes + +Default value: 1 + +##### `full_refresh_on_yum` + +Data type: `Integer` + +rhsm.full_refresh_on_yum +Used directly in rhsm.conf template +1 for Satellite 6 +0 for RHSM + +Default value: 0 + +##### `pool` + +Data type: `String` + +Attach system to a specific pool instead of auto attach to compatible subscriptions + +Default value: `undef` + +##### `proxy_hostname` + +Data type: `String` + +Proxy hostname + +Default value: `undef` + +##### `proxy_port` + +Data type: `Integer` + +Proxy port + +Default value: `undef` + +##### `proxy_user` + +Data type: `String` + +Proxy user + +Default value: `undef` + +##### `proxy_password` + +Data type: `String` + +Proxy password + +Default value: `undef` + +##### `baseurl` + +Data type: `String` + +Base URL for rhsm, default provided + +Default value: 'https://cdn.redhat.com' + +##### `package_ensure` + +Data type: `String` + +Whether to install subscription-manager + +Default value: 'latest' + +##### `enabled_repo_ids` + +Data type: `Optional[Array[String]]` + +nabled_repo_ids [Array[String] +A listing of the Repo IDs to provide to the subscription-manager repo +--enable command. + +Default value: [] + +## Defined types + +### rhsm::repo + +rhsm::repo + +Target file is /etc/yum.repos.d/redhat.repo + +Copyright 2014 Ger Apeldoorn, unless otherwise noted. + +#### Examples + +##### + +```puppet +::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-extras-rpms": } +``` + diff --git a/manifests/init.pp b/manifests/init.pp index 9bddf1a..75bcdb2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -38,8 +38,6 @@ # @param proxy_password [String] Proxy password # @param baseurl [String] Base URL for rhsm, default provided # @param package_ensure [String] Whether to install subscription-manager -# @param repo_extras [Boolean] Enable extras repository -# @param repo_optional [Boolean] Enable optional repository # @param enabled_repo_ids [Array[String] # A listing of the Repo IDs to provide to the subscription-manager repo # --enable command. From 5af20081a9ad36af610f60863e351f6939146a56 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 15:25:49 -0400 Subject: [PATCH 06/13] Repo List Merge Strategy Configure the enabled_repo_ids array to merge unique values when searching in hiera. --- data/common.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index 5611ebb..1ce9a68 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,3 +1,4 @@ --- -# Define an empty array so we don't error -rhsm::enabled_repo_ids: +lookup_options: + rhsm::enabled_repo_ids: + merge: 'unique' From 523b653af5fa3980d02bb3b235662d195cf64ee9 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 17 Sep 2018 17:02:53 -0400 Subject: [PATCH 07/13] Trailing Comma Argument Correction This has been updated to meet the build-requirements defined by travis. --- spec/classes/init_spec.rb | 14 +++++++------- spec/defines/repo_spec.rb | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 99b90f6..1a991fa 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -14,7 +14,7 @@ let :params do { rh_password: 'password', - rh_user: 'username', + rh_user: 'username' } end @@ -24,13 +24,13 @@ it { is_expected.to contain_exec('sm yum clean all') } it do is_expected.to contain_exec('RHSM-register').with( - command: "subscription-manager register --name='#{facts[:fqdn]}' --username='username' --password='password'", + command: "subscription-manager register --name='#{facts[:fqdn]}' --username='username' --password='password'" ) end it do is_expected.to contain_exec('RHSM-subscribe').with( - command: 'subscription-manager attach --auto', + command: 'subscription-manager attach --auto' ) end end @@ -39,13 +39,13 @@ let :params do { org: 'org', - activationkey: 'key', + activationkey: 'key' } end it do is_expected.to contain_exec('RHSM-register').with( - command: "subscription-manager register --name='#{facts[:fqdn]}' --org='org' --activationkey='key'", + command: "subscription-manager register --name='#{facts[:fqdn]}' --org='org' --activationkey='key'" ) end end @@ -57,8 +57,8 @@ rh_user: 'username', enabled_repo_ids: [ 'rhel-7-server-rpms', - 'rhel-7-server-optional-rpms', - ], + 'rhel-7-server-optional-rpms' + ] } end diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index 5cf85ab..5a7864a 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -5,8 +5,8 @@ let(:facts) do facts.merge( 'rhsm' => { - 'enabled_repo_ids' => [], - }, + 'enabled_repo_ids' => [] + } ) end @@ -17,7 +17,7 @@ it { is_expected.to contain_exec('RHSM-enable_rhel-7-server-rpms').with( - command: 'subscription-manager repos --enable rhel-7-server-rpms', + command: 'subscription-manager repos --enable rhel-7-server-rpms' ) } end @@ -29,7 +29,7 @@ it { is_expected.to contain_exec('RHSM-enable_rhel-7-optional-rpms').with( - command: 'subscription-manager repos --enable rhel-7-optional-rpms', + command: 'subscription-manager repos --enable rhel-7-optional-rpms' ) } end @@ -41,9 +41,9 @@ facts.merge( 'rhsm' => { 'enabled_repo_ids' => [ - 'rhel-7-optional-rpms', - ], - }, + 'rhel-7-optional-rpms' + ] + } ) end From 25bdbb773b3f833ba9a63ef5d3058dac3e2008d5 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Tue, 18 Sep 2018 09:33:06 -0400 Subject: [PATCH 08/13] Documentation & Minor PDK Related Unroll This change includes some minor tweaks to the readme file as well as adding in a build status and puppet version badge. --- .rspec | 2 +- README.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.rspec b/.rspec index 16f9cdb..8c18f1a 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---color --format documentation +--color diff --git a/README.md b/README.md index 66cfd8f..65e04ba 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # rhsm +[![Build Status](https://travis-ci.org/voxpupuli/puppet-rhsm.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-rhsm)[![Version](https://img.shields.io/puppetforge/v/puppet/rhsm.svg)](https://forge.puppet.com/puppet/rhsm) + ## Overview This module registers your systems with RedHat Subscription Management. @@ -53,7 +55,7 @@ The proxy settings will be used to register the system and as connection option ### Enabled Repos -A string array of repo IDs can now be provided as an argument to the class definition. This list will be used to enable the target repos if that has not already occurred. +A string array of repo IDs can be provided as an argument to the class definition. This list will be used to enable the target repos if that has not already occurred. The following example enables the server and optional RPMs: From 0d804c95913d4524bca7ee80f48984ca8dbfb04c Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Tue, 18 Sep 2018 10:20:55 -0400 Subject: [PATCH 09/13] Fact Backward Compatibility Added in the original rhsm_repos and rhsm_subscription_type facts for backward compatibility. These facts are now derived from the new rhsm structured fact to avoid doubling work. --- lib/facter/rhsm.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/facter/rhsm.rb b/lib/facter/rhsm.rb index 1e3e31f..fb3f49b 100644 --- a/lib/facter/rhsm.rb +++ b/lib/facter/rhsm.rb @@ -24,3 +24,24 @@ end end end + +# Backward compatibility +Facter.add('rhsm_repos') do + confine :os do |os| + os['name'] == 'RedHat' + end + + setcode do + Facter.value(:rhsm)[:enabled_repo_ids] + end +end + +Facter.add('rhsm_subscription_type') do + confine :os do |os| + os['name'] == 'RedHat' + end + + setcode do + Facter.value(:rhsm)[:subscription_type] + end +end From 2876510284195e4fdace10aeadec02828925ef85 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Fri, 21 Sep 2018 10:08:24 -0400 Subject: [PATCH 10/13] Redhat Family Support Added an explicit check to the enabled repos facts such that the fact will only be calculated if the subscription-manager command exists. This allows the fact to run on CentOS machines which have subscription-manager installed and prevents errors on those that do not. --- lib/facter/rhsm.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/facter/rhsm.rb b/lib/facter/rhsm.rb index fb3f49b..c71a385 100644 --- a/lib/facter/rhsm.rb +++ b/lib/facter/rhsm.rb @@ -1,16 +1,18 @@ Facter.add(:rhsm, type: :aggregate) do confine :os do |os| - os['name'] == 'RedHat' + os['family'] == 'RedHat' end # List the currently enabled repositories - chunk(:enabled_repo_ids) do - repos = Array.[] - repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") - repo_list.each_line do |line| - repos.push(line.strip) + if File.exist? '/usr/bin/subscription-manager' + chunk(:enabled_repo_ids) do + repos = Array.[] + repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") + repo_list.each_line do |line| + repos.push(line.strip) + end + { enabled_repo_ids: repos } end - { enabled_repo_ids: repos } end # Determine the subscription type @@ -28,7 +30,7 @@ # Backward compatibility Facter.add('rhsm_repos') do confine :os do |os| - os['name'] == 'RedHat' + os['family'] == 'RedHat' end setcode do @@ -38,7 +40,7 @@ Facter.add('rhsm_subscription_type') do confine :os do |os| - os['name'] == 'RedHat' + os['family'] == 'RedHat' end setcode do From ae3ee6926335c3da8e49b4636654b6f6060fcc81 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Fri, 21 Sep 2018 10:24:28 -0400 Subject: [PATCH 11/13] rhsm Fact Spacing Issue An incorrect indendation was left within the enabled_repo_ids chunk when the test for subscription-manager was moved outside of the chunk. Should be all set now. --- lib/facter/rhsm.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/facter/rhsm.rb b/lib/facter/rhsm.rb index c71a385..237286d 100644 --- a/lib/facter/rhsm.rb +++ b/lib/facter/rhsm.rb @@ -7,10 +7,10 @@ if File.exist? '/usr/bin/subscription-manager' chunk(:enabled_repo_ids) do repos = Array.[] - repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") - repo_list.each_line do |line| - repos.push(line.strip) - end + repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'") + repo_list.each_line do |line| + repos.push(line.strip) + end { enabled_repo_ids: repos } end end From 0cf14cd847cb41eb51cd9a514e8a553c5a56bdae Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Sun, 23 Sep 2018 14:21:13 -0400 Subject: [PATCH 12/13] Revisions per Tim The following corrections are included in this commit: * enabled_repo_ids is nolonger optional, however, an empty array can be provided * Legacy syntax left in previous releases has been removed * PDK conversions which were accidentally committed have been removed * Compile with all deps is now selected. --- README.md | 16 ++++++++++++++-- manifests/init.pp | 4 ++-- manifests/repo.pp | 2 +- spec/default_facts.yml | 10 ++++++++-- spec/defines/repo_spec.rb | 6 +++--- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 65e04ba..9c1841f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,16 @@ # rhsm -[![Build Status](https://travis-ci.org/voxpupuli/puppet-rhsm.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-rhsm)[![Version](https://img.shields.io/puppetforge/v/puppet/rhsm.svg)](https://forge.puppet.com/puppet/rhsm) +[![Build Status](https://travis-ci.org/voxpupuli/puppet-rhsm.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-rhsm) [![Version](https://img.shields.io/puppetforge/v/puppet/rhsm.svg)](https://forge.puppet.com/puppet/rhsm) -## Overview +#### Table of Contents + +1. [Description](#description) +2. [Setup](#setup) +3. [Usage](#usage) +4. [Limitations](#limitations) +5. [Development](#development) + +## Description This module registers your systems with RedHat Subscription Management. @@ -103,3 +111,7 @@ class { 'rhsm': ## Limitations Well, only RedHat is supported :) + +## Development + +Some general guidelines on PR structure can be found [here](https://voxpupuli.org/docs/#reviewing-a-module-pr). diff --git a/manifests/init.pp b/manifests/init.pp index 75bcdb2..937d359 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -73,7 +73,7 @@ $manage_repos = 1, $full_refresh_on_yum = 0, $package_ensure = 'latest', - Optional[Array[String]] $enabled_repo_ids = [], + Array[String[1]] $enabled_repo_ids = [], ) { if ($rh_user == undef and $rh_password == undef) and ($org == undef and $activationkey == undef) { @@ -159,7 +159,7 @@ unless(empty($enabled_repo_ids)) { $enabled_repo_ids.each | $repo_id | { - ::rhsm::repo { $repo_id: + rhsm::repo { $repo_id: require => Exec['RHSM-subscribe'], } } diff --git a/manifests/repo.pp b/manifests/repo.pp index 656d457..279fef7 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -14,7 +14,7 @@ ) { # Check to see if the title is an enabled repo unless(empty($facts['rhsm'])) { - if ! ($title in $facts['rhsm']['enabled_repo_ids']) { + unless($title in $facts['rhsm']['enabled_repo_ids']) { exec { "RHSM-enable_${title}": command => "subscription-manager repos --enable ${title}", path => '/bin:/usr/bin:/usr/sbin', diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 3248be5..13c4165 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -1,6 +1,12 @@ -# Use default_module_facts.yml for module specific facts. +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config # -# Facts specified here will override the values provided by rspec-puppet-facts. +# use default_module_facts.yaml for module specific +# facts. +# +# Hint if using with rspec-puppet-facts ("on_supported_os.each"): +# if a same named fact exists in facterdb it will be overridden. --- concat_basedir: "/tmp" ipaddress: "172.16.254.254" diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index 5a7864a..350e892 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -13,7 +13,7 @@ context 'enabling server rpms' do let(:title) { 'rhel-7-server-rpms' } - it { is_expected.to compile } + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_exec('RHSM-enable_rhel-7-server-rpms').with( @@ -25,7 +25,7 @@ context 'enabling optional rpms' do let(:title) { 'rhel-7-optional-rpms' } - it { is_expected.to compile } + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_exec('RHSM-enable_rhel-7-optional-rpms').with( @@ -47,7 +47,7 @@ ) end - it { is_expected.to compile } + it { is_expected.to compile.with_all_deps } it { is_expected.not_to contain_exec('RHSM-enable_rhel-7-optional-rpms') } end From 066fbd24d5f51db9bb3ca2f77121e03d7b118d86 Mon Sep 17 00:00:00 2001 From: Phil DeMonaco Date: Mon, 24 Sep 2018 09:24:48 -0400 Subject: [PATCH 13/13] Formatting Alignment of the equal signs on the interface to the primary class. --- manifests/init.pp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 937d359..751a053 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -54,25 +54,25 @@ # @author Ger Apeldoorn # class rhsm ( - $rh_user = undef, - $rh_password = undef, - $org = undef, - $activationkey = undef, - $pool = undef, - $proxy_hostname = undef, - $proxy_port = undef, - $proxy_user = undef, - $proxy_password = undef, - $baseurl = 'https://cdn.redhat.com', - $servername = 'subscription.rhsm.redhat.com', - $serverprefix = '/subscription', - $serverport = 443, - $ca_cert_dir = '/etc/rhsm/ca/', - $repo_ca_cert_filename = 'redhat-uep.pem', - $repo_ca_cert_source = undef, - $manage_repos = 1, - $full_refresh_on_yum = 0, - $package_ensure = 'latest', + $rh_user = undef, + $rh_password = undef, + $org = undef, + $activationkey = undef, + $pool = undef, + $proxy_hostname = undef, + $proxy_port = undef, + $proxy_user = undef, + $proxy_password = undef, + $baseurl = 'https://cdn.redhat.com', + $servername = 'subscription.rhsm.redhat.com', + $serverprefix = '/subscription', + $serverport = 443, + $ca_cert_dir = '/etc/rhsm/ca/', + $repo_ca_cert_filename = 'redhat-uep.pem', + $repo_ca_cert_source = undef, + $manage_repos = 1, + $full_refresh_on_yum = 0, + $package_ensure = 'latest', Array[String[1]] $enabled_repo_ids = [], ) {