From 68dec29df3c32fe5a42e4be8d03b8c4ed57051b8 Mon Sep 17 00:00:00 2001 From: "Dr. Nick" Date: Tue, 8 Dec 2020 07:12:04 -0500 Subject: [PATCH] rhn_register: added force option to allow forced registering (#1454) (#1455) * rhn_register: added force option to allow forced registering (#1454) * rhn_register: added disable=bad-option-value to pylint disables for backwards compat * rhn_register: including version_added for force parameter Co-authored-by: Felix Fontein * [1455] added changelog fragment * removed unnecessary pylint disables * Updated changelogs/fragments/1455-rhn-register-force.yml to have issue # instead of PR # Co-authored-by: Amin Vakil Co-authored-by: Felix Fontein Co-authored-by: Amin Vakil --- .../fragments/1455-rhn-register-force.yml | 2 ++ plugins/modules/packaging/os/rhn_register.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1455-rhn-register-force.yml diff --git a/changelogs/fragments/1455-rhn-register-force.yml b/changelogs/fragments/1455-rhn-register-force.yml new file mode 100644 index 0000000000..9fe46d45b0 --- /dev/null +++ b/changelogs/fragments/1455-rhn-register-force.yml @@ -0,0 +1,2 @@ +minor_changes: + - rhn_register - added ``force`` parameter to allow forced registering (https://github.com/ansible-collections/community.general/issues/1454). diff --git a/plugins/modules/packaging/os/rhn_register.py b/plugins/modules/packaging/os/rhn_register.py index dfc408a5cb..08e9a99e9a 100644 --- a/plugins/modules/packaging/os/rhn_register.py +++ b/plugins/modules/packaging/os/rhn_register.py @@ -49,6 +49,12 @@ options: description: - Supply an profilename for use with registration. type: str + force: + description: + - Force registration, even if system is already registered. + type: bool + default: no + version_added: 2.0.0 ca_cert: description: - Supply a custom ssl CA certificate file for use with registration. @@ -114,6 +120,14 @@ EXAMPLES = r''' username: joe_user password: somepass channels: rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1 + +- name: Force-register as user with password to ensure registration is current on server + community.general.rhn_register: + state: present + username: joe_user + password: somepass + server_url: https://xmlrpc.my.satellite/XMLRPC + force: yes ''' RETURN = r''' @@ -346,6 +360,7 @@ def main(): ca_cert=dict(type='path', aliases=['sslcacert']), systemorgid=dict(type='str'), enable_eus=dict(type='bool', default=False), + force=dict(type='bool', default=False), nopackages=dict(type='bool', default=False), channels=dict(type='list', elements='str', default=[]), ), @@ -365,6 +380,7 @@ def main(): password = module.params['password'] state = module.params['state'] + force = module.params['force'] activationkey = module.params['activationkey'] profilename = module.params['profilename'] sslcacert = module.params['ca_cert'] @@ -395,7 +411,7 @@ def main(): module.fail_json(msg="Missing arguments, If registering without an activationkey, must supply username or password") # Register system - if rhn.is_registered: + if rhn.is_registered and not force: module.exit_json(changed=False, msg="System already registered.") try: