From 47892a0034ae6869b5e9f46f4a7f00cf68759b57 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 26 Jan 2017 19:22:30 +0100 Subject: [PATCH] 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 --- .../packaging/os/redhat_subscription.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/packaging/os/redhat_subscription.py b/lib/ansible/modules/packaging/os/redhat_subscription.py index 0b56c6eafbf..e0fbe01642e 100644 --- a/lib/ansible/modules/packaging/os/redhat_subscription.py +++ b/lib/ansible/modules/packaging/os/redhat_subscription.py @@ -28,7 +28,7 @@ description: 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: @@ -136,6 +136,7 @@ EXAMPLES = ''' - 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 @@ -143,6 +144,7 @@ EXAMPLES = ''' - 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 @@ -249,7 +251,7 @@ class Rhsm(RegistrationBase): 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, @@ -273,7 +275,7 @@ class Rhsm(RegistrationBase): 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 @@ -287,13 +289,12 @@ class Rhsm(RegistrationBase): 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') @@ -331,7 +332,7 @@ class Rhsm(RegistrationBase): 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 @@ -341,7 +342,7 @@ class Rhsm(RegistrationBase): 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): @@ -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 @@ -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: