diff --git a/README.md b/README.md index d43c039..e6afc8f 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ register. Both cannot be provided and will cause an error. - **lifecycleenv**: which lifecycle environment to join at registration time (incompatible with using activation keys) - **autosubscribe**: Enable automatic subscription to repositories based on default Pool settings. Must be false when using an activation key unless specifying a service level. - **servicelevel**: provide automatic attachment to a service level in Satellite. Not applicable to katello installations. +- **release**: The release command sets a sticky OS version to use when installing or updating packages. This sets a preference for the minor version of the OS, such as 6.2 or 6.3. This can prevent unplanned or unsupported operating system version upgrades when an IT environment must maintain a certified configuration. - **force**: Should the registration be forced. Use this option with caution, setting it true will cause the system to be unregistered before running 'subscription-manager register'. Default value `false`. ### rhsm_register Examples diff --git a/tests/init.pp b/examples/init.pp similarity index 100% rename from tests/init.pp rename to examples/init.pp diff --git a/lib/puppet/provider/rhsm_register/subscription_manager.rb b/lib/puppet/provider/rhsm_register/subscription_manager.rb index 0e19656..af1625b 100755 --- a/lib/puppet/provider/rhsm_register/subscription_manager.rb +++ b/lib/puppet/provider/rhsm_register/subscription_manager.rb @@ -32,7 +32,7 @@ def subscription_attach Puppet.debug("This server will be attached to a service level") begin subscription_manager(['attach', - "--servicelevel=#{@resource[:servicelevel]}", '--auto']) + "--servicelevel=#{@resource[:servicelevel]}", '--auto']) rescue Puppet::ExecutionFailure => e Puppet.debug("Auto-attach returned: #{e}") end @@ -43,15 +43,15 @@ def subscription_attach # This builds the command using a helper method and attempts to # deal with expected non-zero return codes from subscription-manager. def register - Puppet.debug("This server will be registered") - # Command will fail with various return codes on re-registration - # RETCODE 1 for new registrations to new servers with an old registration - # RETCODE 2 for re-registrations to the same server after unregister - begin - subscription_manager(build_register_parameters) - rescue Puppet::ExecutionFailure => e - Puppet.debug("Registration returned: #{e}") - end + Puppet.debug("This server will be registered") + # Command will fail with various return codes on re-registration + # RETCODE 1 for new registrations to new servers with an old registration + # RETCODE 2 for re-registrations to the same server after unregister + begin + subscription_manager(build_register_parameters) + rescue Puppet::ExecutionFailure => e + Puppet.debug("Registration returned: #{e}") + end end # Completely remove the registration locally and attempt to notify the server. @@ -69,7 +69,7 @@ def unregister def flush if exists? if self.identity.nil? or self.identity == :absent - # no valid registration + # no valid registration register subscription_attach elsif @property_hash[:name] and @property_hash[:name] != @resource[:name] @@ -81,9 +81,9 @@ def flush # trying to re-register if (@property_hash[:force].nil? or @property_hash[:force] == :absent or @property_hash[:force] == false) and - (@resource[:force].nil? or @resource[:force] == :absent or - @resource[:force] == false) - self.fail("Require force => true to register already registered server") + (@resource[:force].nil? or @resource[:force] == :absent or + @resource[:force] == false) + self.fail("Require force => true to register already registered server") end register subscription_attach @@ -168,14 +168,15 @@ def build_register_parameters params = [] user = @resource[:username] key = @resource[:activationkey] + release = @resource[:release] if (user.nil? and key.nil?) or (user == :absent and key == :absent) or (user == '' and key == '') - self.fail("Need an activation key or a username and password. Was given user '#{user}' and key '#{key}'") - end - if bothset(user, key) - self.fail("Only provide an activation key or username and password not both. Was given user '#{user}' and key '#{key}'") - end + self.fail("Need an activation key or a username and password. Was given user '#{user}' and key '#{key}'") + end + if bothset(user, key) + self.fail("Only provide an activation key or username and password not both. Was given user '#{user}' and key '#{key}'") + end if (@resource[:org].nil? or @resource[:org] == :absent) - self.fail("The 'org' paramater is required to register the system") + self.fail("The 'org' paramater is required to register the system") end params << "register" params << "--force" if @resource[:force] and @resource[:force] != :absent @@ -190,10 +191,13 @@ def build_register_parameters # no autosubscribe with keys, see attach step instead end if ((!@resource[:lifecycleenv].nil? and !@resource[:lifecycleenv] == :absent) and - (@resource[:activationkey].nil? or @resource[:activationkey] == :absent)) - params << "--environment" << @resource[:lifecycleenv] + (@resource[:activationkey].nil? or @resource[:activationkey] == :absent)) + params << "--environment" << @resource[:lifecycleenv] end params << "--org" << @resource[:org] + if !release.nil? + params << "--release" << release + end return params end @@ -203,9 +207,9 @@ def build_register_parameters def self.certified? if File.exists?('/etc/pki/consumer/cert.pem') or File.exists?('/etc/pki/consumer/key.pem') - true + true else - false + false end end diff --git a/lib/puppet/type/rhsm_register.rb b/lib/puppet/type/rhsm_register.rb index 92f5107..f629d66 100755 --- a/lib/puppet/type/rhsm_register.rb +++ b/lib/puppet/type/rhsm_register.rb @@ -86,6 +86,10 @@ desc "A service level for automatic attachement with Satellite servers." end + newparam(:release) do + desc "The release command sets a sticky OS version to use when installing or updating packages." + end + newparam(:org) do desc "The organization the system should be assigned to." validate do |value| diff --git a/manifests/config.pp b/manifests/config.pp index f53653d..4d67c1a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -20,12 +20,13 @@ if $::subscription_manager::activationkey != undef and $::subscription_manager::activationkey != '' { $_settings = { - 'pool' => $::subscription_manager::pool, - 'autosubscribe' => $::subscription_manager::autosubscribe, - 'force' => $::subscription_manager::force, - 'org' => $::subscription_manager::org, - 'servicelevel' => $::subscription_manager::servicelevel, - 'activationkey' => $::subscription_manager::activationkey, + 'pool' => $::subscription_manager::pool, + 'autosubscribe' => $::subscription_manager::autosubscribe, + 'force' => $::subscription_manager::force, + 'org' => $::subscription_manager::org, + 'servicelevel' => $::subscription_manager::servicelevel, + 'activationkey' => $::subscription_manager::activationkey, + 'release' => $::subscription_manager::release, } } else { if $::subscription_manager::username != undef and @@ -40,7 +41,9 @@ 'servicelevel' => $::subscription_manager::servicelevel, 'username' => $::subscription_manager::username, 'password' => $::subscription_manager::password, - 'lifecycleenv' => $::subscription_manager::lifecycleenv, } + 'lifecycleenv' => $::subscription_manager::lifecycleenv, + 'release' => $::subscription_manager::release, + } } else { $_settings = {} } diff --git a/manifests/init.pp b/manifests/init.pp index 1892e19..f63c2a3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -43,6 +43,10 @@ # An activation key to use for registration of the agent to the server. # Conflicts with the username and password registration method. # +# @param release pin a certain release when registering a server +# * `release` +# The release command sets a sticky OS version to use when installing or updating packages. +# # @param pool a pool or RedHat Entitlement to automatically use # * `pool` # A subscription pool or RedHat Entitlement to associate with this system. @@ -124,6 +128,7 @@ String $username = '', String $password = '', String $activationkey = '', + String $release = '', String $pool = '', String $lifecycleenv = 'library', Variant[String, Boolean, Enum['yes','no']] $autosubscribe = false, diff --git a/spec/unit/provider/rhsm_register/subscription_manager_spec.rb b/spec/unit/provider/rhsm_register/subscription_manager_spec.rb index 127d5b4..6456920 100755 --- a/spec/unit/provider/rhsm_register/subscription_manager_spec.rb +++ b/spec/unit/provider/rhsm_register/subscription_manager_spec.rb @@ -213,6 +213,17 @@ ["register", "--force", "--username", "foo", "--password", "bar", "--autosubscribe", "--org", "foo"]) end + it 'should build a command with a release' do + res = Puppet::Type.type(:rhsm_register).new( + :name => title, + :ensure => :present, + :activationkey => fake_key, + :org => 'foo', + :release => '7.3', + :provider => :subscription_manager,) + expect(res.provider.build_register_parameters).to eq( + ["register", "--activationkey", "1-my-activation-key", "--org", "foo", "--release", "7.3"]) + end end describe 'self.instances' do diff --git a/spec/unit/type/rhsm_register_spec.rb b/spec/unit/type/rhsm_register_spec.rb index c19262b..97a319d 100755 --- a/spec/unit/type/rhsm_register_spec.rb +++ b/spec/unit/type/rhsm_register_spec.rb @@ -28,7 +28,7 @@ end [ :username, :password, :org, :activationkey, :lifecycleenv, - :pool, :servicelevel ].each { |params| + :pool, :servicelevel, :release ].each { |params| context "for #{params}" do it "should be of type paramter" do expect(described_class.attrtype(params)).to eq(:param)