Skip to content

Properly detect all HTTP errors.#2462

Draft
nomike wants to merge 1 commit intoF5Networks:develfrom
nomike:improve-http-error-handling
Draft

Properly detect all HTTP errors.#2462
nomike wants to merge 1 commit intoF5Networks:develfrom
nomike:improve-http-error-handling

Conversation

@nomike
Copy link

@nomike nomike commented Apr 14, 2025

Currently, the code only checks for 400 errors in which case an exception is raised.

When the HTTP token expires during a request though, the BigIP responds with a 401 error.

This leads to ugly error messages like this one, which does in no way indicate what's really going on:

Traceback (most recent call last):\n  File \"/home/nomike/.ansible/tmp/ansible-tmp-1744365130.8715017-1746843-240028148910036/AnsiballZ_bigip_virtual_server.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/nomike/.ansible/tmp/ansible-tmp-1744365130.8715017-1746843-240028148910036/AnsiballZ_bigip_virtual_server.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/nomike/.ansible/tmp/ansible-tmp-1744365130.8715017-1746843-240028148910036/AnsiballZ_bigip_virtual_server.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server', init_globals=dict(_module_fqn='ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3882, in <module>\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3875, in main\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3511, in exec_module\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3524, in present\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3547, in update\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3555, in should_update\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3585, in _update_changed_options\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3158, in compare\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 3289, in profiles\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 2066, in profiles\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 1838, in _handle_ssl_profile_nuances\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 1409, in _is_server_ssl_profile\n  File \"/tmp/ansible_bigip_virtual_server_payload_c7vueyp4/ansible_bigip_virtual_server_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_virtual_server.py\", line 1400, in _read_current_serverssl_profiles_from_device\nKeyError: 'items'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

With this patch exceptions are raise for 401 errors too and for all other possible HTTP errors (e.g. BigIP becoming unresponsive while being accessed via an HTTP proxy, which would result in a 503 error).

Error messages now mean something:

fatal: [bigipip.server.lan]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "msg": "401 Client Error: X-F5-Auth-Token has expired. for url: https://bigipip.server.lan:443/mgmt/tm/ltm/profile/client-ssl/"}

@nomike
Copy link
Author

nomike commented Apr 15, 2025

I just figured out, that this breaks creating resources which do not yet exist.
So this PR should not be merged for now. I will look into this.

@nomike nomike marked this pull request as draft April 15, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant