nutanix / nutanix.ansible

Official Nutanix Ansible collections
GNU General Public License v3.0
64 stars 36 forks source link

add msg if API response can't be converted #486

Closed konstruktoid closed 6 days ago

konstruktoid commented 3 months ago

This PR makes the return msg a bit more helpful when the API response can't be converted to json.

Pre- and post-patch:

$ ansible-playbook -ihosts cert.yml 2>/dev/null

PLAY [Clusters_Info playbook] **********************************************************************************************************************

TASK [Getting all clusters - validate_certs True] ***********************************************************************************************************************
fatal: [prism]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "error": null, "msg": "Failed to convert API response to json", "response": null, "status_code": -1}
...ignoring

TASK [Print clusters] ******************************************************************************************************
ok: [prism] => {
    "msg": {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "error": null,
        "failed": true,
        "msg": "Failed to convert API response to json",
        "response": null,
        "status_code": -1
    }
}

TASK [Getting all clusters - validate_certs False] *******************************************************************************************************************
ok: [prism]

TASK [Print clusters] *********************************************************************************************
ok: [prism] => {
    "msg": "API version: 3.1"
}

PLAY RECAP **************************************************************************************************************
prism                      : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1
$ ansible-playbook -ihosts cert.yml 2>/dev/null

PLAY [Clusters_Info playbook] ****************************************************************************************************************************

TASK [Getting all clusters - validate_certs True] ****************************************************************************************************************************
fatal: [prism]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "error": null, "msg": "Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)>", "response": null, "status_code": -1}
...ignoring

TASK [Print clusters] *****************************************************************************************************************************
ok: [prism] => {
    "msg": {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "error": null,
        "failed": true,
        "msg": "Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)>",
        "response": null,
        "status_code": -1
    }
}

TASK [Getting all clusters - validate_certs False] *************************************************************************************************************************
ok: [prism]

TASK [Print clusters] *****************************************************************************************************
ok: [prism] => {
    "msg": "API version: 3.1"
}

PLAY RECAP **************************************************************************************************************
prism                      : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1
bhati-pradeep commented 2 months ago

Thank you for raising PR

konstruktoid commented 2 months ago

Added a try:/catch: and I assume that any error message will be > 2, but it will skip any empty ("") messages.

marathe-99 commented 2 months ago

Is that problem is resolved??

bhati-pradeep commented 2 months ago

Is that problem is resolved??

Not yet @marathe-99, this will go in next maintenance release.