# Buggy code
def get_disk_inventory(self):
    result = {}
    disks_details = []
    controller_list = []

    # Find Storage service
    response = self.get_request(self.root_uri + self.systems_uri)
    if response["ret"] is False:
        return response
    data = response["data"]

    if "SimpleStorage" not in data:
        return {"ret": False, "msg": "SimpleStorage resource not found"}

    # Get a list of all storage controllers and build respective URIs
    storage_uri = data["SimpleStorage"]["@odata.id"]
    response = self.get_request(self.root_uri + storage_uri)
    if response["ret"] is False:
        return response
    result["ret"] = True
    data = response["data"]

    for controller in data["Members"]:
        controller_list.append(controller["@odata.id"])

    for c in controller_list:
        uri = self.root_uri + c
        response = self.get_request(uri)
        if response["ret"] is False:
            return response
        data = response["data"]

        for device in data["Devices"]:
            disks_details.append(
                dict(
                    Controller=data["Name"],
                    Name=device["Name"],
                    Manufacturer=device["Manufacturer"],
                    Model=device["Model"],
                    State=device["Status"]["State"],
                    Health=device["Status"]["Health"],
                )
            )
    result["entries"] = disks_details
    return result


# Traceback (KeyError)
OS / ENVIRONMENT
Gentoo GNU/Linux x86_64, Fedora GNU/Linux x86_64
STEPS TO REPRODUCE
Use this playbook (user, password and baseuri should be set to Redfish API credentials and endpoint):
- hosts: localhost
gather_facts: false
vars:
baseuri: redfish_api_entrypoint
user: test
password: test
tasks:
- name: Get all information available in all categories
redfish_facts:
category: all
command: all
baseuri: "{{ baseuri }}"
user: "{{ user }}"
password: "{{ password }}"
EXPECTED RESULTS
Facts about Redfish service are gathered and stored for later use.
ACTUAL RESULTS
Task failed during execution.
ansible-playbook 2.7.0b1.post0
config file = None
configured module search path = [u'/home/tadej/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/tadej/xlab/ansible/ansible/venv2/lib/python2.7/site-packages/ansible
executable location = /home/tadej/xlab/ansible/ansible/venv2/bin/ansible-playbook
python version = 2.7.15 (default, Jul 16 2018, 15:01:34) [GCC 7.3.0]
No config file found; using defaults
setting up inventory plugins
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Loading callback plugin default of type stdout, v2.0 from /home/tadej/xlab/ansible/ansible/venv2/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: facts.yml ***************************************************************************************************************************************************
1 plays in facts.yml

PLAY [localhost] ******************************************************************************************************************************************************
META: ran handlers

TASK [Get all information available in all categories] ****************************************************************************************************************
task path: /home/tadej/xlab/wwt/ansible-playbooks/redfish-ansible-2.7-tests/facts.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tadej
<127.0.0.1> EXEC /bin/sh -c 'echo ~tadej &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597 `" &amp;&amp; echo ansible-tmp-1536174086.57-2660084232597="` echo /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597 `" ) &amp;&amp; sleep 0'
Using module file /home/tadej/xlab/ansible/ansible/venv2/lib/python2.7/site-packages/ansible/modules/remote_management/redfish/redfish_facts.py
<127.0.0.1> PUT /home/tadej/.ansible/tmp/ansible-local-2609QiUJEu/tmpED3mGl TO /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/ /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/tadej/xlab/ansible/ansible/venv2/bin/python2 /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py", line 113, in <module>
_ansiballz_main()
File "/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py", line 48, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/tmp/ansible_redfish_facts_payload_Yfsq9X/__main__.py", line 267, in <module>
File "/tmp/ansible_redfish_facts_payload_Yfsq9X/__main__.py", line 206, in main
File "/tmp/ansible_redfish_facts_payload_Yfsq9X/ansible_redfish_facts_payload.zip/ansible/module_utils/redfish_utils.py", line 861, in get_psu_inventory
KeyError: u'Model'

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/tadej/.ansible/tmp/ansible-tmp-1536174086.57-2660084232597/AnsiballZ_redfish_facts.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_redfish_facts_payload_Yfsq9X/__main__.py\", line 267, in <module>\n  File \"/tmp/ansible_redfish_facts_payload_Yfsq9X/__main__.py\", line 206, in main\n  File \"/tmp/ansible_redfish_facts_payload_Yfsq9X/ansible_redfish_facts_payload.zip/ansible/module_utils/redfish_utils.py\", line 861, in get_psu_inventory\nKeyError: u'Model'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
to retry, use: --limit @/home/tadej/xlab/wwt/ansible-playbooks/redfish-ansible-2.7-tests/facts.retry

PLAY RECAP ************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

# Fixed code
def get_disk_inventory(self):
    result = {}
    controller_list = []
    disk_results = []
    # Get these entries, but does not fail if not found
    properties = ["Name", "Manufacturer", "Model", "Status", "CapacityBytes"]

    # Find Storage service
    response = self.get_request(self.root_uri + self.systems_uri)
    if response["ret"] is False:
        return response
    data = response["data"]

    if "SimpleStorage" not in data:
        return {"ret": False, "msg": "SimpleStorage resource not found"}

    # Get a list of all storage controllers and build respective URIs
    storage_uri = data["SimpleStorage"]["@odata.id"]
    response = self.get_request(self.root_uri + storage_uri)
    if response["ret"] is False:
        return response
    result["ret"] = True
    data = response["data"]

    for controller in data["Members"]:
        controller_list.append(controller["@odata.id"])

    for c in controller_list:
        uri = self.root_uri + c
        response = self.get_request(uri)
        if response["ret"] is False:
            return response
        data = response["data"]

        for device in data["Devices"]:
            disk = {}
            for property in properties:
                if property in device:
                    disk[property] = device[property]
            disk_results.append(disk)
    result["entries"] = disk_results
    return result