sensu / sensu-go-ansible

Official Ansible module for Sensu Go
GNU General Public License v3.0
36 stars 28 forks source link

The `version` function in the module utils seems to use unsupported HTTP method #346

Closed asachs01 closed 1 year ago

asachs01 commented 1 year ago

Bug description In internal ref https://secure.helpscout.net/conversation/2215756593/31316?folderId=5845954, it was reported that the collection fails when attempting to get the version of the backend. Upon further investigation, it appears that the client utility uses an supported HTTP method to hit the /version endpoint, which results in an HTTP 405. The method used is HEAD, which isn't supported. There must be an explicit GET.

How to reproduce the bug To reproduce outside of the collection:

  1. curl -I http://localhost:8080/version
  2. Observe the HTTP 405
  3. curl -X GET http://localhost:8080/version
  4. Observe the HTTP 200

Component versions

fguimond commented 1 year ago

More notes:

The issue I'm having is with the Ansible collection repository, with a clean install from scratch, for a single-node backend. We're moving from Chef to Ansible and trying to get our QA pipeline working. The playbook is attached. sensu_backend_info is just a dict we grab from Hashicorp Vault. The API key for the user admin is created successfully, but creation of the user ansible is where it dies, as far as I can tell here: https://github.com/sensu/sensu-go-ansible/blob/96055c9d4a519415bc2a9e52c2198772d84cba01/plugins/module_utils/client.py#L43.

Thanks for making the issue, but I think there may be some confusion. The 405 was definitely an issue on my end with the wrong header for curl, but using the playbook gets a 400 error--and I haven't been able to replicate that on 8080, just 3000. It's possible the playbook would be using the wrong port, but that wouldn't make a lot of sense given that it's just making API calls. Regardless, thanks for putting this up there.

juremedvesek commented 1 year ago

Hi, thanks for posting a bug.

For easier debugging I summarized what collection calls and uses.

Default port used by collection is 8080. https://github.com/sensu/sensu-go-ansible/blob/96055c9d4a519415bc2a9e52c2198772d84cba01/plugins/module_utils/arguments.py#L29 It may be changed by setting parameter SENSU_URL.

Method used by collection is GET. Meaning, that yours command curl -X GET http://localhost:8080/version should directly replicate collections call (in case that SENSU_URL was not changed).

You can get debug log by setting environment variable SENSU_ANSIBLE_DEBUG. https://github.com/sensu/sensu-go-ansible/blob/96055c9d4a519415bc2a9e52c2198772d84cba01/plugins/module_utils/debug.py#L14 Other instructions are written in file.

In one of next releases of collection we will also add verbose log of HTTP failures to ansible output (in case of -vvvv) . Which should help a lot with debugging.

asachs01 commented 1 year ago

@juremedvesek thanks for that update. I followed up on the issue on our end, and it looks like they were using the insecure default and didn't set SENSU_URL. Everything is good now and I'll close this out.