# Buggy code
def generate_admin_dict(array):
    admin_info = {}
    admins = array.list_admins()
    for admin in range(0, len(admins)):
        admin_name = admins[admin]["name"]
        admin_info[admin_name] = {
            "type": admins[admin]["type"],
            "role": admins[admin]["role"],
        }
    return admin_info


# Traceback (PureHTTPError)
fatal: [localhost]: FAILED! => {
“changed”: false,
“module_stderr”: “/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\n/Library/Python/2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n  InsecureRequestWarning)\nTraceback (most recent call last):\n  File \“/Users/mal/.ansible/tmp/ansible-tmp-1567731055.62-142309712025409/AnsiballZ_purefa_facts.py\“, line 114, in <module>\n    _ansiballz_main()\n  File \“/Users/mal/.ansible/tmp/ansible-tmp-1567731055.62-142309712025409/AnsiballZ_purefa_facts.py\“, line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \“/Users/mal/.ansible/tmp/ansible-tmp-1567731055.62-142309712025409/AnsiballZ_purefa_facts.py\“, line 49, in invoke_module\n    imp.load_module(‘__main__‘, mod, module, MOD_DESC)\n  File \“/var/folders/r6/q1bv9j2109n37_k4qgr10ln40000gn/T/ansible_purefa_facts_payload_uyda_z/__main__.py\“, line 800, in <module>\n  File \“/var/folders/r6/q1bv9j2109n37_k4qgr10ln40000gn/T/ansible_purefa_facts_payload_uyda_z/__main__.py\“, line 761, in main\n  File \“/var/folders/r6/q1bv9j2109n37_k4qgr10ln40000gn/T/ansible_purefa_facts_payload_uyda_z/__main__.py\“, line 358, in generate_default_dict\n  File \“/Library/Python/2.7/site-packages/purestorage/purestorage.py\“, line 1769, in list_admins\n    return self._list_admin(**kwargs)\n  File \“/Library/Python/2.7/site-packages/purestorage/purestorage.py\“, line 1751, in _list_admin\n    return self._request(\“GET\“, \“admin\“, kwargs)\n  File \“/Library/Python/2.7/site-packages/purestorage/purestorage.py\“, line 197, in _request\n    raise PureHTTPError(self._target, str(self._rest_version), response)\npurestorage.purestorage.PureHTTPError: PureHTTPError status code 400 returned by REST version 1.12 at 10.52.11.30: BAD REQUEST\n[{\“msg\“: \“rest_service.py: argument --publickey or --api-token is required\“}]\n”,
“module_stdout”: “”,
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,
“rc”: 1
}

# Fixed code
def generate_admin_dict(array):
    admin_info = {}
    api_version = array._list_available_rest_versions()
    if ADMIN_API_VERSION in api_version:
        admins = array.list_admins()
        for admin in range(0, len(admins)):
            admin_name = admins[admin]["name"]
            admin_info[admin_name] = {
                "type": admins[admin]["type"],
                "role": admins[admin]["role"],
            }
    return admin_info