Fixes #6548 correct issues from rhn_register refactoring

This commit is contained in:
James Tanner 2014-03-18 21:21:18 -04:00
parent 8899c74aaf
commit 324a943e12

View file

@ -84,10 +84,14 @@ try:
except ImportError, e: except ImportError, e:
module.fail_json(msg="Unable to import up2date_client. Is 'rhn-client-tools' installed?\n%s" % e) module.fail_json(msg="Unable to import up2date_client. Is 'rhn-client-tools' installed?\n%s" % e)
# INSERT REDHAT SNIPPETS
from ansible.module_utils.redhat import *
# INSERT COMMON SNIPPETS
from ansible.module_utils.basic import *
class Rhn(RegistrationBase): class Rhn(RegistrationBase):
def __init__(self, module, username=None, password=None): def __init__(self, username=None, password=None):
RegistrationBase.__init__(self, username, password) RegistrationBase.__init__(self, username, password)
self.config = self.load_config() self.config = self.load_config()
@ -193,21 +197,26 @@ class Rhn(RegistrationBase):
Register system to RHN. If enable_eus=True, extended update Register system to RHN. If enable_eus=True, extended update
support will be requested. support will be requested.
''' '''
register_cmd = "/usr/sbin/rhnreg_ks --username '%s' --password '%s' --force" % (self.username, self.password) register_cmd = "/usr/sbin/rhnreg_ks --username='%s' --password='%s' --force" % (self.username, self.password)
if self.module.params.get('server_url', None):
register_cmd += " --serverUrl=%s" % self.module.params.get('server_url')
if enable_eus: if enable_eus:
register_cmd += " --use-eus-channel" register_cmd += " --use-eus-channel"
if activationkey is not None: if activationkey is not None:
register_cmd += " --activationkey '%s'" % activationkey register_cmd += " --activationkey '%s'" % activationkey
# FIXME - support --profilename # FIXME - support --profilename
# FIXME - support --systemorgid # FIXME - support --systemorgid
rc, stdout, stderr = self.module.run_command(register_command, check_rc=True) rc, stdout, stderr = self.module.run_command(register_cmd, check_rc=True, use_unsafe_shell=True)
def api(self, method, *args): def api(self, method, *args):
''' '''
Convenience RPC wrapper Convenience RPC wrapper
''' '''
if not hasattr(self, 'server') or self.server is None: if not hasattr(self, 'server') or self.server is None:
url = "https://xmlrpc.%s/rpc/api" % self.hostname if self.hostname != 'rhn.redhat.com':
url = "https://%s/rpc/api" % self.hostname
else:
url = "https://xmlrpc.%s/rpc/api" % self.hostname
self.server = xmlrpclib.Server(url, verbose=0) self.server = xmlrpclib.Server(url, verbose=0)
self.session = self.server.auth.login(self.username, self.password) self.session = self.server.auth.login(self.username, self.password)
@ -270,6 +279,7 @@ def main():
rhn.configure(module.params['server_url']) rhn.configure(module.params['server_url'])
activationkey = module.params['activationkey'] activationkey = module.params['activationkey']
channels = module.params['channels'] channels = module.params['channels']
rhn.module = module
# Ensure system is registered # Ensure system is registered
if state == 'present': if state == 'present':
@ -288,10 +298,10 @@ def main():
rhn.enable() rhn.enable()
rhn.register(module.params['enable_eus'] == True, activationkey) rhn.register(module.params['enable_eus'] == True, activationkey)
rhn.subscribe(channels) rhn.subscribe(channels)
except CommandException, e: except Exception, e:
module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, e)) module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, e))
else:
module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname) module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname)
# Ensure system is *not* registered # Ensure system is *not* registered
if state == 'absent': if state == 'absent':
@ -300,14 +310,10 @@ def main():
else: else:
try: try:
rhn.unregister() rhn.unregister()
except CommandException, e: except Exception, e:
module.fail_json(msg="Failed to unregister: %s" % e) module.fail_json(msg="Failed to unregister: %s" % e)
else:
module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname)
module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.redhat import *
main() main()