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