Minor adjustments to subscription_manager and rhnreg_ks

reviewable/pr18780/r1
James Laska 12 years ago
parent 3e05292fa3
commit 8593409767

@ -309,15 +309,15 @@ class Rhn(RegistrationBase):
def main():
# Load RHSM configuration from file
reg = Rhn()
# Read system RHN configuration
rhn = Rhn()
module = AnsibleModule(
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent']),
username = dict(default=None, required=False),
password = dict(default=None, required=False),
server_url = dict(default=reg.config.get_option('serverURL'), required=False),
server_url = dict(default=rhn.config.get_option('serverURL'), required=False),
activationkey = dict(default=None, required=False),
enable_eus = dict(default=False, type='bool'),
channels = dict(default=[], type='list'),
@ -325,9 +325,9 @@ def main():
)
state = module.params['state']
reg.username = module.params['username']
reg.password = module.params['password']
reg.configure(module.params['server_url'])
rhn.username = module.params['username']
rhn.password = module.params['password']
rhn.configure(module.params['server_url'])
activationkey = module.params['activationkey']
channels = module.params['channels']
@ -335,35 +335,35 @@ def main():
if state == 'present':
# Check for missing parameters ...
if not (activationkey or reg.username or reg.password):
module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, reg.username, reg.password))
if not activationkey and not (reg.username and reg.password):
if not (activationkey or rhn.username or rhn.password):
module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, rhn.username, rhn.password))
if not activationkey and not (rhn.username and rhn.password):
module.fail_json(msg="Missing arguments, If registering without an activationkey, must supply username or password")
# Register system
if reg.is_registered:
if rhn.is_registered:
module.exit_json(changed=False, msg="System already registered.")
else:
try:
reg.enable()
reg.register(module.params['enable_eus'] == True, activationkey)
reg.subscribe(channels)
rhn.enable()
rhn.register(module.params['enable_eus'] == True, activationkey)
rhn.subscribe(channels)
except CommandException, e:
module.fail_json(msg="Failed to register with '%s': %s" % (reg.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'." % reg.hostname)
module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname)
# Ensure system is *not* registered
if state == 'absent':
if not reg.is_registered:
if not rhn.is_registered:
module.exit_json(changed=False, msg="System already unregistered.")
else:
try:
reg.unregister()
rhn.unregister()
except CommandException, e:
module.fail_json(msg="Failed to unregister: %s" % e)
else:
module.exit_json(changed=True, msg="System successfully unregistered from %s." % reg.hostname)
module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname)
# include magic from lib/ansible/module_common.py

@ -145,7 +145,7 @@ class Rhsm(RegistrationBase):
RegistrationBase.__init__(self, username, password)
self.config = self._read_config()
def _read_config(rhsm_conf='/etc/rhsm/rhsm.conf'):
def _read_config(self, rhsm_conf='/etc/rhsm/rhsm.conf'):
'''
Load RHSM configuration from /etc/rhsm/rhsm.conf.
Returns:
@ -154,8 +154,7 @@ class Rhsm(RegistrationBase):
# Read RHSM defaults ...
cp = ConfigParser.ConfigParser()
if os.path.isfile(rhsm_conf):
cp.read(rhsm_conf)
cp.read(rhsm_conf)
# Add support for specifying a default value w/o having to standup some configuration
# Yeah, I know this should be subclassed ... but, oh well

Loading…
Cancel
Save