From 36c52dba82cff21999f6e600718fb023af6f27d7 Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Fri, 29 Mar 2019 15:46:49 -0400 Subject: [PATCH 1/9] Checking registration via api instead of local file. --- tasks/main.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 5629116..20341b1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -66,20 +66,29 @@ when: redhat_portal_username is defined become: true -- name: Check status of Insights .register file - stat: path=/etc/{{ insights_name }}/.registered +- name: Check status of Insights registration via API + command: "{{ insights_name }} --status" + register: api_status_result become: true - register: reg_file_task + +- name: Assign registration status to variable + set_fact: + reg_status: "{{ api_status_result.stderr }}" - name: Unregister if we are setting the display_name, and we have already registered - command: "{{ insights_name }} --unregister" + block: + - command: "{{ insights_name }} --unregister" + - set_fact: + reg_status: "unregistered" when: - insights_display_name is defined - - reg_file_task.stat.exists == true + - '"Insights API confirms registration." in reg_status' become: true - name: Register to the Red Hat Access Insights Service if necessary - command: "{{ insights_name }} --register {{ '--display-name='+insights_display_name if insights_display_name is defined else '' }} creates=/etc/{{ insights_name }}/.registered" + command: "{{ insights_name }} --register {{ '--display-name='+insights_display_name if insights_display_name is defined else '' }}" + when: + - '"Insights API confirms registration." not in reg_status' become: true - name: Change permissions of Insights Config directory so that Insights System ID can be read From b6e610bdcea3ff41bf309f6fbe74b26c020d4efb Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Fri, 29 Mar 2019 16:01:14 -0400 Subject: [PATCH 2/9] Adding names to each action within the block for better output. --- tasks/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 20341b1..074e89e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -77,8 +77,10 @@ - name: Unregister if we are setting the display_name, and we have already registered block: - - command: "{{ insights_name }} --unregister" - - set_fact: + - name: Unregister to update display name + command: "{{ insights_name }} --unregister" + - name: Update registration status + set_fact: reg_status: "unregistered" when: - insights_display_name is defined From ec183a30a949198154b7f3e2f9c4726ca5a4f815 Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Mon, 1 Apr 2019 15:10:29 -0400 Subject: [PATCH 3/9] Removing references to redhat-access-insights --- tasks/main.yml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 074e89e..bbea18c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,34 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -- name: Check for 'insights-client' RPM availability - yum: - list: insights-client - register: yum_list_task - become: true - -- name: Install 'insights-client' if it is available +- name: Install 'insights-client' yum: name: insights-client - when: yum_list_task.results|length > 0 become: true - name: Set Insights Config Name to 'insights-client' set_fact: insights_name: 'insights-client' - when: yum_list_task.results|length > 0 - become: true - -- name: Install 'redhat-access-insights' if 'insights-client' is not available - yum: - name: redhat-access-insights - when: yum_list_task.results|length == 0 - become: true - -- name: Set Insights Config Name to 'redhat-access-insights' - set_fact: - insights_name: 'redhat-access-insights' - when: yum_list_task.results|length == 0 become: true - name: Configure username in Insights' Config file @@ -105,7 +85,6 @@ mode: og=r become: true - - name: Create directory for ansible custom facts file: state: directory From fcf6e0379b62b7332fcc75de1107ad1423cf9a60 Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Tue, 2 Apr 2019 16:14:23 -0400 Subject: [PATCH 4/9] Refactored registration into a new module found at library/insights_registration.py --- library/insights_registration.py | 108 +++++++++++++++++++++++++++++++ tasks/main.yml | 29 ++------- 2 files changed, 112 insertions(+), 25 deletions(-) create mode 100644 library/insights_registration.py diff --git a/library/insights_registration.py b/library/insights_registration.py new file mode 100644 index 0000000..71dc857 --- /dev/null +++ b/library/insights_registration.py @@ -0,0 +1,108 @@ +#!/usr/bin/python + +# Copyright: (c) 2018, Terry Jones +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} + +DOCUMENTATION = ''' +--- +module: insights_registration + +short_description: This module registers the insights client + +description: + - This module will check the current registration status, unregister if needed, + and then register the insights client (and update the display_name if needed) + +options: + insights_name: + description: + - For now, this is just 'insights-client', but it could change in the future + so having it as a variable is just preparing for that + required: true + display_name: + description: + - When registering with insights an optional display_name can be configured + required: false + +author: + - Jason Stephens (@Jason-RH) +''' + +EXAMPLES = ''' +# Register a fresh install +- name: Register the insights client on a fresh install + insights_registration: + insights_name: "{{ insights_name }}" + +# Register a fresh install with a display name +- name: Register the insights client with display name + insights_registration: + insights_name: "{{ insights_name }}" + display_name: "{{ insights_display_name }}" +''' + +RETURN = ''' +original_message: + description: The original name param that was passed in + type: str +message: + description: The output message that the sample module generates +''' + +from ansible.module_utils.basic import AnsibleModule +import subprocess + +def run_module(): + # define available arguments/parameters a user can pass to the module + module_args = dict( + insights_name=dict(type='str', required=True), + display_name=dict(type='str', required=False, default='') + ) + + result = dict( + changed=False, + original_message='', + message='' + ) + + module = AnsibleModule( + argument_spec=module_args, + supports_check_mode=True + ) + + if module.check_mode: + return result + + result['original_message'] = 'Attempting to register insights-client' + result['message'] = 'No registration changes have been made' + + insights_name = module.params['insights_name'] + display_name = module.params['display_name'] + + reg_status = subprocess.call([insights_name, '--status']) + + if display_name and reg_status is 0: + subprocess.call([insights_name, '--unregister']) + reg_status = 1 + result['changed'] = True + result['message'] = 'Insights-client has been unregistered' + + if reg_status is not 0: + display_name_arg = '--display-name=' + display_name + subprocess.call([insights_name, '--register', display_name_arg]) + result['changed'] = True + result['message'] = 'Insights-client has been registered' + + module.exit_json(**result) + +def main(): + run_module() + +if __name__ == '__main__': + main() diff --git a/tasks/main.yml b/tasks/main.yml index bbea18c..d2d2ba5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -46,33 +46,12 @@ when: redhat_portal_username is defined become: true -- name: Check status of Insights registration via API - command: "{{ insights_name }} --status" - register: api_status_result +- name: Register Insights Client + insights_registration: + insights_name: "{{ insights_name }}" + display_name: "{{ insights_display_name if insights_display_name is defined else '' }}" become: true -- name: Assign registration status to variable - set_fact: - reg_status: "{{ api_status_result.stderr }}" - -- name: Unregister if we are setting the display_name, and we have already registered - block: - - name: Unregister to update display name - command: "{{ insights_name }} --unregister" - - name: Update registration status - set_fact: - reg_status: "unregistered" - when: - - insights_display_name is defined - - '"Insights API confirms registration." in reg_status' - become: true - -- name: Register to the Red Hat Access Insights Service if necessary - command: "{{ insights_name }} --register {{ '--display-name='+insights_display_name if insights_display_name is defined else '' }}" - when: - - '"Insights API confirms registration." not in reg_status' - become: true - - name: Change permissions of Insights Config directory so that Insights System ID can be read file: path: /etc/{{ insights_name }} From d2ced5342b90af8efc2f836617a33a0e91030afe Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Wed, 3 Apr 2019 15:49:47 -0400 Subject: [PATCH 5/9] Adding module + action plugin for insights client configuration --- action_plugins/insights_config.py | 40 +++++++++++++++++++++++++ library/insights_config.py | 49 +++++++++++++++++++++++++++++++ tasks/main.yml | 27 +++++------------ 3 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 action_plugins/insights_config.py create mode 100644 library/insights_config.py diff --git a/action_plugins/insights_config.py b/action_plugins/insights_config.py new file mode 100644 index 0000000..cd048c0 --- /dev/null +++ b/action_plugins/insights_config.py @@ -0,0 +1,40 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action import ActionBase + + +class ActionModule(ActionBase): + + def run(self, tmp=None, task_vars=None): + + result = super(ActionModule, self).run(tmp, task_vars) + + insights_name = self._task.args.get('insights_name') + + config_vars = dict( + username = self._task.args.get('username', None), + password = self._task.args.get('password', None), + auto_config = self._task.args.get('auto_config', None), + authmethod = self._task.args.get('authmethod', None) + ) + + for k, v in config_vars.items(): + if v: + new_module_args = dict( + path = '/etc/' + insights_name + '/' + insights_name + '.conf', + section = insights_name, + option = k, + value = v, + no_extra_spaces = True, + state = "present" + ) + result.update(self._execute_module( + module_name='ini_file', + module_args=new_module_args, + task_vars=task_vars, + tmp=tmp + )) + + return result + diff --git a/library/insights_config.py b/library/insights_config.py new file mode 100644 index 0000000..8da46e7 --- /dev/null +++ b/library/insights_config.py @@ -0,0 +1,49 @@ +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} + +DOCUMENTATION = ''' +--- +module: insights_config +short_description: This module handles initial configuration of the insights client on install +description: + - Supply values for various configuration options that you would like to use. On install + this module will add those values to the insights-client.conf file prior to registering. +version_added: "3.0" +options: + insights_name: + description: + - For now this is just 'insights-client', but that could change in the future if the + product name changes. + required: true + username: + description: + - Insights basic auth username. If defined this will change, set, or remove the username + in the insights configuration. To remove a username set this value to an empty string. + required: false + password: + description: + - Insights basic auth password. If defined this will change, set, or remove the password + in the insights configuration. To remove a password set this value to an empty string. + required: false + auto_config: + description: + - Attempt to auto-configure the network connection with Satellite or RHSM. Default is True. + required: false + authmethod: + description: + - Authentication method for the Portal (BASIC, CERT). Default is BASIC. Note: when + auto_config is enabled, CERT will be used if RHSM or Satellite is detected. + required: true +''' + +EXAMPLES = ''' +- insights_config: + insights_name: 'insights-client' or "{{ insights_name }}" + username: "rhn_support" or "{{ redhat_portal_username }}" if passing in as a role variable + password: "rhn_password" or "{{ redhat_portal_password }}" if passing in as a role variable + auto_config: True + authmethod: BASIC +''' diff --git a/tasks/main.yml b/tasks/main.yml index d2d2ba5..83a341e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -24,26 +24,13 @@ insights_name: 'insights-client' become: true -- name: Configure username in Insights' Config file - ini_file: - path: /etc/{{ insights_name }}/{{ insights_name }}.conf - section: "{{ insights_name }}" - option: username - value: "{{ redhat_portal_username }}" - no_extra_spaces: true - state: "{{ 'present' if redhat_portal_username else 'absent' }}" - when: redhat_portal_username is defined - become: true - -- name: Configure password in Insights Config file - ini_file: - path: /etc/{{ insights_name }}/{{ insights_name }}.conf - section: "{{ insights_name }}" - option: password - value: "{{ redhat_portal_password }}" - no_extra_spaces: true - state: "{{ 'present' if redhat_portal_username else 'absent' }}" - when: redhat_portal_username is defined +- name: Set Insights Configuration Values + insights_config: + insights_name: 'insights-client' + username: "{{ redhat_portal_username }}" + password: "{{ redhat_portal_password }}" + auto_config: "{{ auto_config }}" + authmethod: "{{ authmethod }}" become: true - name: Register Insights Client From e5f0cc6f51dd2485eaafe7fc03b9a2613127a425 Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Thu, 4 Apr 2019 11:19:07 -0400 Subject: [PATCH 6/9] This commit is cleaning up a lot. Removed insights_name as a required parameter everywhere. Added additional examples. --- action_plugins/insights_config.py | 5 ++- library/insights_config.py | 42 +++++++++++++------ ...s_registration.py => insights_register.py} | 40 +++++++++++------- tasks/main.yml | 15 ++----- 4 files changed, 61 insertions(+), 41 deletions(-) rename library/{insights_registration.py => insights_register.py} (62%) diff --git a/action_plugins/insights_config.py b/action_plugins/insights_config.py index cd048c0..8c447e5 100644 --- a/action_plugins/insights_config.py +++ b/action_plugins/insights_config.py @@ -10,13 +10,14 @@ def run(self, tmp=None, task_vars=None): result = super(ActionModule, self).run(tmp, task_vars) - insights_name = self._task.args.get('insights_name') + insights_name = self._task.args.get('insights_name', 'insights-client') config_vars = dict( username = self._task.args.get('username', None), password = self._task.args.get('password', None), auto_config = self._task.args.get('auto_config', None), - authmethod = self._task.args.get('authmethod', None) + authmethod = self._task.args.get('authmethod', None), + display_name = self._task.args.get('display_name', None) ) for k, v in config_vars.items(): diff --git a/library/insights_config.py b/library/insights_config.py index 8da46e7..4a45520 100644 --- a/library/insights_config.py +++ b/library/insights_config.py @@ -13,11 +13,6 @@ this module will add those values to the insights-client.conf file prior to registering. version_added: "3.0" options: - insights_name: - description: - - For now this is just 'insights-client', but that could change in the future if the - product name changes. - required: true username: description: - Insights basic auth username. If defined this will change, set, or remove the username @@ -36,14 +31,37 @@ description: - Authentication method for the Portal (BASIC, CERT). Default is BASIC. Note: when auto_config is enabled, CERT will be used if RHSM or Satellite is detected. - required: true + required: false + display_name: + description: + - Custom display name to appear in the Insights web UI. Only used on machine registration. + Blank by default. + required: false + insights_name: + description: + - For now, this is just 'insights-client', but it could change in the future so having + it as a variable is just preparing for that. + required: false ''' EXAMPLES = ''' -- insights_config: - insights_name: 'insights-client' or "{{ insights_name }}" - username: "rhn_support" or "{{ redhat_portal_username }}" if passing in as a role variable - password: "rhn_password" or "{{ redhat_portal_password }}" if passing in as a role variable - auto_config: True - authmethod: BASIC +- name: Configure the insights client to register with username and password + insights_config: + username: "rhn_support" or "{{ redhat_portal_username }}" if passing in as a role variable + password: "rhn_password" or "{{ redhat_portal_password }}" + auto_config: False or "{{ auto_config }}" + authmethod: BASIC or "{{ authmethod }}" + become: true + +- name: Configure the insights client to register with RHSM and no display name + insights_config: + become: true + +Note: The above example calls the insights_config module with no parameters. This is because auto_config defaults to True +which in turn forces the client to try RHSM (or Satellite) + +- name: Configure the insights client to register with RHSM and a display name + insights_config: + display_name: "nice_name" or "{{ insights_display_name }}" if passing in as a role variable + become: true ''' diff --git a/library/insights_registration.py b/library/insights_register.py similarity index 62% rename from library/insights_registration.py rename to library/insights_register.py index 71dc857..9c9760d 100644 --- a/library/insights_registration.py +++ b/library/insights_register.py @@ -11,7 +11,7 @@ DOCUMENTATION = ''' --- -module: insights_registration +module: insights_register short_description: This module registers the insights client @@ -24,10 +24,12 @@ description: - For now, this is just 'insights-client', but it could change in the future so having it as a variable is just preparing for that - required: true + required: false display_name: description: - - When registering with insights an optional display_name can be configured + - This option is here to enable registering with a display_name outside of using + a configuration file. Some may be used to doing it this way so I left this in as + an optional parameter. required: false author: @@ -35,24 +37,31 @@ ''' EXAMPLES = ''' -# Register a fresh install +# Register a fresh install (no parameters required) - name: Register the insights client on a fresh install - insights_registration: - insights_name: "{{ insights_name }}" + insights_register: -# Register a fresh install with a display name +# Register a fresh install with a display name (if choosing not to use a configuration file) - name: Register the insights client with display name - insights_registration: - insights_name: "{{ insights_name }}" + insights_register: display_name: "{{ insights_display_name }}" + +# Register a fresh install of redhat-access-insights (this is not a 100% automated process) +- name: Register redhat-access-insights + insights_register: + insights_name: 'redhat-access-insights' + +Note: The above example for registering redhat-access-insights requires that the playbook be +changed to install redhat-access-insights and that redhat-access-insights is also passed into +the insights_config module and that the file paths be changed when using the file module ''' RETURN = ''' original_message: - description: The original name param that was passed in + description: Just a sentence declaring that there is a registration attempt type: str message: - description: The output message that the sample module generates + description: The output message that the module generates ''' from ansible.module_utils.basic import AnsibleModule @@ -61,7 +70,7 @@ def run_module(): # define available arguments/parameters a user can pass to the module module_args = dict( - insights_name=dict(type='str', required=True), + insights_name=dict(type='str', required=False, default='insights-client'), display_name=dict(type='str', required=False, default='') ) @@ -91,13 +100,12 @@ def run_module(): subprocess.call([insights_name, '--unregister']) reg_status = 1 result['changed'] = True - result['message'] = 'Insights-client has been unregistered' + result['message'] = insights_name + ' has been unregistered' if reg_status is not 0: - display_name_arg = '--display-name=' + display_name - subprocess.call([insights_name, '--register', display_name_arg]) + subprocess.call([insights_name, '--register']) result['changed'] = True - result['message'] = 'Insights-client has been registered' + result['message'] = insights_name + ' has been registered' module.exit_json(**result) diff --git a/tasks/main.yml b/tasks/main.yml index 83a341e..100611c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -19,35 +19,28 @@ name: insights-client become: true -- name: Set Insights Config Name to 'insights-client' - set_fact: - insights_name: 'insights-client' - become: true - - name: Set Insights Configuration Values insights_config: - insights_name: 'insights-client' username: "{{ redhat_portal_username }}" password: "{{ redhat_portal_password }}" auto_config: "{{ auto_config }}" authmethod: "{{ authmethod }}" + display_name: "{{ insights_display_name }}" become: true - name: Register Insights Client - insights_registration: - insights_name: "{{ insights_name }}" - display_name: "{{ insights_display_name if insights_display_name is defined else '' }}" + insights_register: become: true - name: Change permissions of Insights Config directory so that Insights System ID can be read file: - path: /etc/{{ insights_name }} + path: /etc/insights-client mode: og=rx become: true - name: Change permissions of machine_id file so that Insights System ID can be read file: - path: /etc/{{ insights_name }}/machine-id + path: /etc/insights-client/machine-id mode: og=r become: true From d5d26e85441437344f9e2909371578d4fb51690c Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Thu, 4 Apr 2019 15:58:34 -0400 Subject: [PATCH 7/9] Adding the omit filter in case these variables are not defined. --- tasks/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 100611c..6853b73 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -21,11 +21,11 @@ - name: Set Insights Configuration Values insights_config: - username: "{{ redhat_portal_username }}" - password: "{{ redhat_portal_password }}" - auto_config: "{{ auto_config }}" - authmethod: "{{ authmethod }}" - display_name: "{{ insights_display_name }}" + username: "{{ redhat_portal_username | default(omit) }}" + password: "{{ redhat_portal_password | default(omit) }}" + auto_config: "{{ auto_config | default(omit) }}" + authmethod: "{{ authmethod | default(omit) }}" + display_name: "{{ insights_display_name | default(omit) }}" become: true - name: Register Insights Client From e1502e6357f4ba4083147fab70dc6f5e6df6767f Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Fri, 5 Apr 2019 11:35:24 -0400 Subject: [PATCH 8/9] Adding state and force_reregister parameters to the insights_register module. --- library/insights_register.py | 79 ++++++++++++++++++++++++++---------- tasks/main.yml | 1 + 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/library/insights_register.py b/library/insights_register.py index 9c9760d..b4d9f6f 100644 --- a/library/insights_register.py +++ b/library/insights_register.py @@ -20,6 +20,11 @@ and then register the insights client (and update the display_name if needed) options: + state: + description: + - Determines whether to register or unregister insights-client + choices: ["present", "absent"] + required: true insights_name: description: - For now, this is just 'insights-client', but it could change in the future @@ -31,24 +36,37 @@ a configuration file. Some may be used to doing it this way so I left this in as an optional parameter. required: false + force_reregister: + description: + - This option should be set to true if you wish to force a reregister of the insights-client. + Note that this will remove the existing machine-id and create a new one. Only use this option + if you are okay with creating a new machine-id. author: - Jason Stephens (@Jason-RH) ''' EXAMPLES = ''' -# Register a fresh install (no parameters required) -- name: Register the insights client on a fresh install +# Normal Register +- name: Register the insights client insights_register: + state: present -# Register a fresh install with a display name (if choosing not to use a configuration file) -- name: Register the insights client with display name +# Force a Reregister (for config changes, etc) +- name: Resgiter the insights client insights_register: - display_name: "{{ insights_display_name }}" + state: present + force_reregister: true + +# Unregister +- name: Unregister the insights client + insights_regsiter: + state: absent -# Register a fresh install of redhat-access-insights (this is not a 100% automated process) +# Register an install of redhat-access-insights (this is not a 100% automated process) - name: Register redhat-access-insights insights_register: + state: present insights_name: 'redhat-access-insights' Note: The above example for registering redhat-access-insights requires that the playbook be @@ -70,8 +88,10 @@ def run_module(): # define available arguments/parameters a user can pass to the module module_args = dict( + state=dict(choices=['present', 'absent'], default='present'), insights_name=dict(type='str', required=False, default='insights-client'), - display_name=dict(type='str', required=False, default='') + display_name=dict(type='str', required=False, default=''), + force_reregister=dict(type='bool', required=False, default=False) ) result = dict( @@ -88,26 +108,41 @@ def run_module(): if module.check_mode: return result - result['original_message'] = 'Attempting to register insights-client' - result['message'] = 'No registration changes have been made' - + state = module.params['state'] insights_name = module.params['insights_name'] display_name = module.params['display_name'] + force_reregister = module.params['force_reregister'] reg_status = subprocess.call([insights_name, '--status']) - if display_name and reg_status is 0: - subprocess.call([insights_name, '--unregister']) - reg_status = 1 - result['changed'] = True - result['message'] = insights_name + ' has been unregistered' - - if reg_status is not 0: - subprocess.call([insights_name, '--register']) - result['changed'] = True - result['message'] = insights_name + ' has been registered' - - module.exit_json(**result) + if state == 'present': + result['original_message'] = 'Attempting to register ' + insights_name + if reg_status == 0 and not force_reregister: + result['changed'] = False + result['message'] = 'The Insights API has determined that this machine is already registered' + module.exit_json(**result) + elif reg_status == 0 and force_reregister: + subprocess.call([insights_name, '--force-reregister']) + result['changed'] = True + result['message'] = 'New machine-id created - ' + insights_name + ' has been registered' + module.exit_json(**result) + else: + subprocess.call([insights_name, '--register']) + result['changed'] = True + result['message'] = insights_name + ' has been registered' + module.exit_json(**result) + + if state == 'absent': + result['original_message'] = 'Attempting to unregister ' + insights_name + if reg_status is not 0: + result['changed'] = False + result['message'] = insights_name + ' is already unregistered' + module.exit_json(**result) + else: + subprocess.call([insights_name, '--unregister']) + result['changed'] = True + result['message'] = insights_name + ' has been unregistered' + module.exit_json(**result) def main(): run_module() diff --git a/tasks/main.yml b/tasks/main.yml index 6853b73..9666466 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -30,6 +30,7 @@ - name: Register Insights Client insights_register: + state: present become: true - name: Change permissions of Insights Config directory so that Insights System ID can be read From 76c8248613f44a075b7f3f4a695dcf662c28c7a1 Mon Sep 17 00:00:00 2001 From: Jason Stephens Date: Fri, 5 Apr 2019 11:36:53 -0400 Subject: [PATCH 9/9] Adding missing required tag in the documentation --- library/insights_register.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/insights_register.py b/library/insights_register.py index b4d9f6f..89de8ec 100644 --- a/library/insights_register.py +++ b/library/insights_register.py @@ -38,9 +38,10 @@ required: false force_reregister: description: - - This option should be set to true if you wish to force a reregister of the insights-client. - Note that this will remove the existing machine-id and create a new one. Only use this option - if you are okay with creating a new machine-id. + - This option should be set to true if you wish to force a reregister of the insights-client. + Note that this will remove the existing machine-id and create a new one. Only use this option + if you are okay with creating a new machine-id. + required: false author: - Jason Stephens (@Jason-RH)