mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
redhat_subscription: Document & enforce org_id (#20548)
* redhat_subscription: enforce the need for org_id when AK is used also update the documentation to reflect that Fixes: #20542 * redhat_subscription: check for existence of subscription-manager
This commit is contained in:
parent
42e63d429c
commit
47892a0034
1 changed files with 17 additions and 13 deletions
|
@ -28,7 +28,7 @@ description:
|
||||||
version_added: "1.2"
|
version_added: "1.2"
|
||||||
author: "Barnaby Court (@barnabycourt)"
|
author: "Barnaby Court (@barnabycourt)"
|
||||||
notes:
|
notes:
|
||||||
- In order to register a system, subscription-manager requires either a username and password, or an activationkey.
|
- In order to register a system, subscription-manager requires either a username and password, or an activationkey and an Organization ID.
|
||||||
requirements:
|
requirements:
|
||||||
- subscription-manager
|
- subscription-manager
|
||||||
options:
|
options:
|
||||||
|
@ -136,6 +136,7 @@ EXAMPLES = '''
|
||||||
- redhat_subscription:
|
- redhat_subscription:
|
||||||
state: present
|
state: present
|
||||||
activationkey: 1-222333444
|
activationkey: 1-222333444
|
||||||
|
org_id: 222333444
|
||||||
pool: '^(Red Hat Enterprise Server|Red Hat Virtualization)$'
|
pool: '^(Red Hat Enterprise Server|Red Hat Virtualization)$'
|
||||||
|
|
||||||
# Update the consumed subscriptions from the previous example (remove the Red
|
# Update the consumed subscriptions from the previous example (remove the Red
|
||||||
|
@ -143,6 +144,7 @@ EXAMPLES = '''
|
||||||
- redhat_subscription:
|
- redhat_subscription:
|
||||||
state: present
|
state: present
|
||||||
activationkey: 1-222333444
|
activationkey: 1-222333444
|
||||||
|
org_id: 222333444
|
||||||
pool: '^Red Hat Enterprise Server$'
|
pool: '^Red Hat Enterprise Server$'
|
||||||
|
|
||||||
# Register as user credentials into given environment (against Red Hat
|
# Register as user credentials into given environment (against Red Hat
|
||||||
|
@ -249,7 +251,7 @@ class Rhsm(RegistrationBase):
|
||||||
Raises:
|
Raises:
|
||||||
* Exception - if error occurs while running command
|
* Exception - if error occurs while running command
|
||||||
'''
|
'''
|
||||||
args = ['subscription-manager', 'config']
|
args = [SUBMAN_CMD, 'config']
|
||||||
|
|
||||||
# Pass supplied **kwargs as parameters to subscription-manager. Ignore
|
# Pass supplied **kwargs as parameters to subscription-manager. Ignore
|
||||||
# non-configuration parameters and replace '_' with '.'. For example,
|
# non-configuration parameters and replace '_' with '.'. For example,
|
||||||
|
@ -273,7 +275,7 @@ class Rhsm(RegistrationBase):
|
||||||
return os.path.isfile('/etc/pki/consumer/cert.pem') and \
|
return os.path.isfile('/etc/pki/consumer/cert.pem') and \
|
||||||
os.path.isfile('/etc/pki/consumer/key.pem')
|
os.path.isfile('/etc/pki/consumer/key.pem')
|
||||||
|
|
||||||
args = ['subscription-manager', 'identity']
|
args = [SUBMAN_CMD, 'identity']
|
||||||
rc, stdout, stderr = self.module.run_command(args, check_rc=False)
|
rc, stdout, stderr = self.module.run_command(args, check_rc=False)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
return True
|
return True
|
||||||
|
@ -287,12 +289,11 @@ class Rhsm(RegistrationBase):
|
||||||
Raises:
|
Raises:
|
||||||
* Exception - if error occurs while running command
|
* Exception - if error occurs while running command
|
||||||
'''
|
'''
|
||||||
args = ['subscription-manager', 'register']
|
args = [SUBMAN_CMD, 'register']
|
||||||
|
|
||||||
# Generate command arguments
|
# Generate command arguments
|
||||||
if activationkey:
|
if activationkey:
|
||||||
args.extend(['--activationkey', activationkey])
|
args.extend(['--activationkey', activationkey])
|
||||||
if org_id:
|
|
||||||
args.extend(['--org', org_id])
|
args.extend(['--org', org_id])
|
||||||
else:
|
else:
|
||||||
if autosubscribe:
|
if autosubscribe:
|
||||||
|
@ -331,7 +332,7 @@ class Rhsm(RegistrationBase):
|
||||||
items = ["--all"]
|
items = ["--all"]
|
||||||
|
|
||||||
if items:
|
if items:
|
||||||
args = ['subscription-manager', 'unsubscribe'] + items
|
args = [SUBMAN_CMD, 'unsubscribe'] + items
|
||||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
||||||
return serials
|
return serials
|
||||||
|
|
||||||
|
@ -341,7 +342,7 @@ class Rhsm(RegistrationBase):
|
||||||
Raises:
|
Raises:
|
||||||
* Exception - if error occurs while running command
|
* Exception - if error occurs while running command
|
||||||
'''
|
'''
|
||||||
args = ['subscription-manager', 'unregister']
|
args = [SUBMAN_CMD, 'unregister']
|
||||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
||||||
|
|
||||||
def subscribe(self, regexp):
|
def subscribe(self, regexp):
|
||||||
|
@ -483,7 +484,9 @@ def main():
|
||||||
consumer_name = dict(default=None, required=False),
|
consumer_name = dict(default=None, required=False),
|
||||||
consumer_id = dict(default=None, required=False),
|
consumer_id = dict(default=None, required=False),
|
||||||
force_register = dict(default=False, type='bool'),
|
force_register = dict(default=False, type='bool'),
|
||||||
)
|
),
|
||||||
|
required_together = [ ['username', 'password'], ['activationkey', 'org_id'] ],
|
||||||
|
mutually_exclusive = [ ['username', 'activationkey'] ],
|
||||||
)
|
)
|
||||||
|
|
||||||
rhsm.module = module
|
rhsm.module = module
|
||||||
|
@ -503,14 +506,15 @@ def main():
|
||||||
consumer_id = module.params["consumer_id"]
|
consumer_id = module.params["consumer_id"]
|
||||||
force_register = module.params["force_register"]
|
force_register = module.params["force_register"]
|
||||||
|
|
||||||
|
global SUBMAN_CMD
|
||||||
|
SUBMAN_CMD = module.get_bin_path('subscription-manager', True)
|
||||||
|
|
||||||
# Ensure system is registered
|
# Ensure system is registered
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
|
||||||
# Check for missing parameters ...
|
# Check for missing parameters ...
|
||||||
if not (activationkey or username or password):
|
if not (activationkey or org_id or username or password):
|
||||||
module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, username, password))
|
module.fail_json(msg="Missing arguments, must supply an activationkey (%s) and Organization ID (%s) or username (%s) and password (%s)" % (activationkey, org_id, username, password))
|
||||||
if not activationkey and not (username and password):
|
|
||||||
module.fail_json(msg="Missing arguments, If registering without an activationkey, must supply username or password")
|
|
||||||
|
|
||||||
# Register system
|
# Register system
|
||||||
if rhsm.is_registered and not force_register:
|
if rhsm.is_registered and not force_register:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue