mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Minor adjustments to subscription_manager and rhnreg_ks
This commit is contained in:
parent
65993e8f35
commit
6059ce34e3
2 changed files with 20 additions and 21 deletions
|
@ -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
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Rhsm(RegistrationBase):
|
||||||
RegistrationBase.__init__(self, username, password)
|
RegistrationBase.__init__(self, username, password)
|
||||||
self.config = self._read_config()
|
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.
|
Load RHSM configuration from /etc/rhsm/rhsm.conf.
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -154,8 +154,7 @@ class Rhsm(RegistrationBase):
|
||||||
|
|
||||||
# Read RHSM defaults ...
|
# Read RHSM defaults ...
|
||||||
cp = ConfigParser.ConfigParser()
|
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
|
# Add support for specifying a default value w/o having to standup some configuration
|
||||||
# Yeah, I know this should be subclassed ... but, oh well
|
# Yeah, I know this should be subclassed ... but, oh well
|
||||||
|
|
Loading…
Reference in a new issue