[PR #6259/c9e11e5c backport][stable-6] redhat_subscription: manually unregister only when registered (#6280)
redhat_subscription: manually unregister only when registered (#6259)
When registering using D-Bus and using a version of subscription-manager
with an unimplemented 'force' option, then unregister manually the
system only if it is registered. 'subscription-manager unregister'
errors out when trying to unregister an already unregistered system.
(cherry picked from commit c9e11e5c0c
)
Co-authored-by: Pino Toscano <ptoscano@redhat.com>
pull/6282/head
parent
6b0cc3c1de
commit
43beaf4b00
|
@ -0,0 +1,4 @@
|
||||||
|
bugfixes:
|
||||||
|
- redhat_subscription - try to unregister only when already registered when ``force_register`` is specified
|
||||||
|
(https://github.com/ansible-collections/community.general/issues/6258,
|
||||||
|
https://github.com/ansible-collections/community.general/pull/6259).
|
|
@ -450,7 +450,7 @@ class Rhsm(RegistrationBase):
|
||||||
self.module.debug('Verified system D-Bus bus as usable')
|
self.module.debug('Verified system D-Bus bus as usable')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def register(self, username, password, token, auto_attach, activationkey, org_id,
|
def register(self, was_registered, username, password, token, auto_attach, activationkey, org_id,
|
||||||
consumer_type, consumer_name, consumer_id, force_register, environment,
|
consumer_type, consumer_name, consumer_id, force_register, environment,
|
||||||
release):
|
release):
|
||||||
'''
|
'''
|
||||||
|
@ -463,7 +463,7 @@ class Rhsm(RegistrationBase):
|
||||||
# There is no support for token-based registration in the D-Bus API
|
# There is no support for token-based registration in the D-Bus API
|
||||||
# of rhsm, so always use the CLI in that case.
|
# of rhsm, so always use the CLI in that case.
|
||||||
if not token and self._can_connect_to_dbus():
|
if not token and self._can_connect_to_dbus():
|
||||||
self._register_using_dbus(username, password, auto_attach,
|
self._register_using_dbus(was_registered, username, password, auto_attach,
|
||||||
activationkey, org_id, consumer_type,
|
activationkey, org_id, consumer_type,
|
||||||
consumer_name, consumer_id,
|
consumer_name, consumer_id,
|
||||||
force_register, environment, release)
|
force_register, environment, release)
|
||||||
|
@ -521,7 +521,7 @@ class Rhsm(RegistrationBase):
|
||||||
|
|
||||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True, expand_user_and_vars=False)
|
rc, stderr, stdout = self.module.run_command(args, check_rc=True, expand_user_and_vars=False)
|
||||||
|
|
||||||
def _register_using_dbus(self, username, password, auto_attach,
|
def _register_using_dbus(self, was_registered, username, password, auto_attach,
|
||||||
activationkey, org_id, consumer_type, consumer_name,
|
activationkey, org_id, consumer_type, consumer_name,
|
||||||
consumer_id, force_register, environment, release):
|
consumer_id, force_register, environment, release):
|
||||||
'''
|
'''
|
||||||
|
@ -570,7 +570,7 @@ class Rhsm(RegistrationBase):
|
||||||
distro_version[0] > 9)):
|
distro_version[0] > 9)):
|
||||||
dbus_force_option_works = True
|
dbus_force_option_works = True
|
||||||
|
|
||||||
if force_register and not dbus_force_option_works:
|
if force_register and not dbus_force_option_works and was_registered:
|
||||||
self.unregister()
|
self.unregister()
|
||||||
|
|
||||||
register_opts = {}
|
register_opts = {}
|
||||||
|
@ -592,7 +592,7 @@ class Rhsm(RegistrationBase):
|
||||||
distro_version[0] >= 9)):
|
distro_version[0] >= 9)):
|
||||||
environment_key = 'environments'
|
environment_key = 'environments'
|
||||||
register_opts[environment_key] = environment
|
register_opts[environment_key] = environment
|
||||||
if force_register and dbus_force_option_works:
|
if force_register and dbus_force_option_works and was_registered:
|
||||||
register_opts['force'] = True
|
register_opts['force'] = True
|
||||||
# Wrap it as proper D-Bus dict
|
# Wrap it as proper D-Bus dict
|
||||||
register_opts = dbus.Dictionary(register_opts, signature='sv', variant_level=1)
|
register_opts = dbus.Dictionary(register_opts, signature='sv', variant_level=1)
|
||||||
|
@ -1137,8 +1137,11 @@ def main():
|
||||||
# Ensure system is registered
|
# Ensure system is registered
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
|
||||||
|
# Cache the status of the system before the changes
|
||||||
|
was_registered = rhsm.is_registered
|
||||||
|
|
||||||
# Register system
|
# Register system
|
||||||
if rhsm.is_registered and not force_register:
|
if was_registered and not force_register:
|
||||||
if syspurpose and 'sync' in syspurpose and syspurpose['sync'] is True:
|
if syspurpose and 'sync' in syspurpose and syspurpose['sync'] is True:
|
||||||
try:
|
try:
|
||||||
rhsm.sync_syspurpose()
|
rhsm.sync_syspurpose()
|
||||||
|
@ -1165,7 +1168,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
rhsm.enable()
|
rhsm.enable()
|
||||||
rhsm.configure(**module.params)
|
rhsm.configure(**module.params)
|
||||||
rhsm.register(username, password, token, auto_attach, activationkey, org_id,
|
rhsm.register(was_registered, username, password, token, auto_attach, activationkey, org_id,
|
||||||
consumer_type, consumer_name, consumer_id, force_register,
|
consumer_type, consumer_name, consumer_id, force_register,
|
||||||
environment, release)
|
environment, release)
|
||||||
if syspurpose and 'sync' in syspurpose and syspurpose['sync'] is True:
|
if syspurpose and 'sync' in syspurpose and syspurpose['sync'] is True:
|
||||||
|
|
Loading…
Reference in New Issue