@ -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