diff --git a/changelogs/fragments/7882-add-redfish-get-service-identification.yml b/changelogs/fragments/7882-add-redfish-get-service-identification.yml new file mode 100644 index 0000000000..463c9a2bc5 --- /dev/null +++ b/changelogs/fragments/7882-add-redfish-get-service-identification.yml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_info - add command ``GetServiceIdentification`` to get service identification (https://github.com/ansible-collections/community.general/issues/7882). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index dadf12c33b..0d6609f8cc 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3365,7 +3365,8 @@ class RedfishUtils(object): inventory = {} # Get these entries, but does not fail if not found properties = ['Id', 'FirmwareVersion', 'ManagerType', 'Manufacturer', 'Model', - 'PartNumber', 'PowerState', 'SerialNumber', 'Status', 'UUID'] + 'PartNumber', 'PowerState', 'SerialNumber', 'ServiceIdentification', + 'Status', 'UUID'] response = self.get_request(self.root_uri + manager_uri) if response['ret'] is False: @@ -3383,6 +3384,30 @@ class RedfishUtils(object): def get_multi_manager_inventory(self): return self.aggregate_managers(self.get_manager_inventory) + def get_service_identification(self, manager): + result = {} + if manager is None: + if len(self.manager_uris) == 1: + manager = self.manager_uris[0].split('/')[-1] + elif len(self.manager_uris) > 1: + entries = self.get_multi_manager_inventory()['entries'] + managers = [m[0]['manager_uri'] for m in entries if m[1].get('ServiceIdentification')] + if len(managers) == 1: + manager = managers[0].split('/')[-1] + else: + self.module.fail_json(msg=[ + "Multiple managers with ServiceIdentification were found: %s" % str(managers), + "Please specify by using the 'manager' parameter in your playbook"]) + elif len(self.manager_uris) == 0: + self.module.fail_json(msg="No manager identities were found") + response = self.get_request(self.root_uri + '/redfish/v1/Managers/' + manager, override_headers=None) + try: + result['service_identification'] = response['data']['ServiceIdentification'] + except Exception as e: + self.module.fail_json(msg="Service ID not found for manager %s" % manager) + result['ret'] = True + return result + def set_session_service(self, sessions_config): if sessions_config is None: return {'ret': False, 'msg': diff --git a/plugins/modules/redfish_info.py b/plugins/modules/redfish_info.py index 3620b5674f..0b39bb6fa8 100644 --- a/plugins/modules/redfish_info.py +++ b/plugins/modules/redfish_info.py @@ -55,6 +55,11 @@ options: - Security token for authenticating to OOB controller. type: str version_added: 2.3.0 + manager: + description: + - Name of manager on OOB controller to target. + type: str + version_added: '8.3.0' timeout: description: - Timeout in seconds for HTTP requests to OOB controller. @@ -248,6 +253,15 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" + - name: Get service identification + community.general.redfish_info: + category: Manager + command: GetServiceIdentification + manager: "{{ manager }}" + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + - name: Get software inventory community.general.redfish_info: category: Update @@ -369,7 +383,7 @@ CATEGORY_COMMANDS_ALL = { "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory", "GetUpdateStatus"], "Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols", - "GetHealthReport", "GetHostInterfaces", "GetManagerInventory"], + "GetHealthReport", "GetHostInterfaces", "GetManagerInventory", "GetServiceIdentification"], } CATEGORY_COMMANDS_DEFAULT = { @@ -395,6 +409,7 @@ def main(): auth_token=dict(no_log=True), timeout=dict(type='int'), update_handle=dict(), + manager=dict(), ), required_together=[ ('username', 'password'), @@ -429,6 +444,9 @@ def main(): # update handle update_handle = module.params['update_handle'] + # manager + manager = module.params['manager'] + # Build root URI root_uri = "https://" + module.params['baseuri'] rf_utils = RedfishUtils(creds, root_uri, timeout, module) @@ -579,6 +597,8 @@ def main(): result["host_interfaces"] = rf_utils.get_hostinterfaces() elif command == "GetManagerInventory": result["manager"] = rf_utils.get_multi_manager_inventory() + elif command == "GetServiceIdentification": + result["service_id"] = rf_utils.get_service_identification(manager) # Return data back module.exit_json(redfish_facts=result)