Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redhat_subscription: Document & enforce org_id #20548

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 17 additions & 13 deletions lib/ansible/modules/packaging/os/redhat_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
version_added: "1.2"
author: "Barnaby Court (@barnabycourt)"
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:
- subscription-manager
options:
Expand Down Expand Up @@ -136,13 +136,15 @@
- redhat_subscription:
state: present
activationkey: 1-222333444
org_id: 222333444
pool: '^(Red Hat Enterprise Server|Red Hat Virtualization)$'

# Update the consumed subscriptions from the previous example (remove the Red
# Hat Virtualization subscription)
- redhat_subscription:
state: present
activationkey: 1-222333444
org_id: 222333444
pool: '^Red Hat Enterprise Server$'

# Register as user credentials into given environment (against Red Hat
Expand Down Expand Up @@ -249,7 +251,7 @@ def configure(self, **kwargs):
Raises:
* Exception - if error occurs while running command
'''
args = ['subscription-manager', 'config']
args = [SUBMAN_CMD, 'config']

# Pass supplied **kwargs as parameters to subscription-manager. Ignore
# non-configuration parameters and replace '_' with '.'. For example,
Expand All @@ -273,7 +275,7 @@ def is_registered(self):
return os.path.isfile('/etc/pki/consumer/cert.pem') and \
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)
if rc == 0:
return True
Expand All @@ -287,13 +289,12 @@ def register(self, username, password, autosubscribe, activationkey, org_id,
Raises:
* Exception - if error occurs while running command
'''
args = ['subscription-manager', 'register']
args = [SUBMAN_CMD, 'register']

# Generate command arguments
if activationkey:
args.extend(['--activationkey', activationkey])
if org_id:
args.extend(['--org', org_id])
args.extend(['--org', org_id])
else:
if autosubscribe:
args.append('--autosubscribe')
Expand Down Expand Up @@ -331,7 +332,7 @@ def unsubscribe(self, serials=None):
items = ["--all"]

if items:
args = ['subscription-manager', 'unsubscribe'] + items
args = [SUBMAN_CMD, 'unsubscribe'] + items
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
return serials

Expand All @@ -341,7 +342,7 @@ def unregister(self):
Raises:
* 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)

def subscribe(self, regexp):
Expand Down Expand Up @@ -483,7 +484,9 @@ def main():
consumer_name = dict(default=None, required=False),
consumer_id = dict(default=None, required=False),
force_register = dict(default=False, type='bool'),
)
),
required_together = [ ['username', 'password'], ['activationkey', 'org_id'] ],
mutually_exclusive = [ ['username', 'activationkey'] ],
)

rhsm.module = module
Expand All @@ -503,14 +506,15 @@ def main():
consumer_id = module.params["consumer_id"]
force_register = module.params["force_register"]

global SUBMAN_CMD
SUBMAN_CMD = module.get_bin_path('subscription-manager', True)

# Ensure system is registered
if state == 'present':

# Check for missing parameters ...
if not (activationkey or username or password):
module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, 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")
if not (activationkey or org_id or username or 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))

# Register system
if rhsm.is_registered and not force_register:
Expand Down