# Buggy code
def get_chassis_power(self):
    result = {}
    key = "Power"

    # Get these entries, but does not fail if not found
    properties = [
        "Name",
        "PowerAllocatedWatts",
        "PowerAvailableWatts",
        "PowerCapacityWatts",
        "PowerConsumedWatts",
        "PowerMetrics",
        "PowerRequestedWatts",
        "RelatedItem",
        "Status",
    ]

    chassis_power_results = []
    # Go through list
    for chassis_uri in self.chassis_uri_list:
        chassis_power_result = {}
        response = self.get_request(self.root_uri + chassis_uri)
        if response["ret"] is False:
            return response
        result["ret"] = True
        data = response["data"]
        if key in data:
            response = self.get_request(self.root_uri + chassis_uri + "/" + key)
            data = response["data"]
            if "PowerControl" in data:
                if len(data["PowerControl"]) > 0:
                    data = data["PowerControl"][0]
                    for property in properties:
                        if property in data:
                            chassis_power_result[property] = data[property]
            else:
                return {"ret": False, "msg": "Key PowerControl not found."}
            chassis_power_results.append(chassis_power_result)
        else:
            return {"ret": False, "msg": "Key Power not found."}

    result["entries"] = chassis_power_results
    return result


# Traceback (KeyError)
TASK [Get Chassis Power] ********************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'data'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1557169030.74096-151454169883598/AnsiballZ_redfish_facts.py\", line 125, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1557169030.74096-151454169883598/AnsiballZ_redfish_facts.py\", line 117, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1557169030.74096-151454169883598/AnsiballZ_redfish_facts.py\", line 51, in invoke_module\n    spec.loader.exec_module(module)\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_redfish_facts_payload_vijwehp0/__main__.py\", line 346, in <module>\n  File \"/tmp/ansible_redfish_facts_payload_vijwehp0/__main__.py\", line 303, in main\n  File \"/tmp/ansible_redfish_facts_payload_vijwehp0/ansible_redfish_facts_payload.zip/ansible/module_utils/redfish_utils.py\", line 1048, in get_chassis_power\nKeyError: 'data'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def get_chassis_power(self):
    result = {}
    key = "Power"

    # Get these entries, but does not fail if not found
    properties = [
        "Name",
        "PowerAllocatedWatts",
        "PowerAvailableWatts",
        "PowerCapacityWatts",
        "PowerConsumedWatts",
        "PowerMetrics",
        "PowerRequestedWatts",
        "RelatedItem",
        "Status",
    ]

    chassis_power_results = []
    # Go through list
    for chassis_uri in self.chassis_uri_list:
        chassis_power_result = {}
        response = self.get_request(self.root_uri + chassis_uri)
        if response["ret"] is False:
            return response
        result["ret"] = True
        data = response["data"]
        if key in data:
            response = self.get_request(self.root_uri + data[key]["@odata.id"])
            data = response["data"]
            if "PowerControl" in data:
                if len(data["PowerControl"]) > 0:
                    data = data["PowerControl"][0]
                    for property in properties:
                        if property in data:
                            chassis_power_result[property] = data[property]
            else:
                return {"ret": False, "msg": "Key PowerControl not found."}
            chassis_power_results.append(chassis_power_result)
        else:
            return {"ret": False, "msg": "Key Power not found."}

    result["entries"] = chassis_power_results
    return result