jaredledvina/sensu-go-ansible

sensu-go-check failed to run

Closed this issue · 4 comments

I try to use sensu-go-check module

  1. Added module path to library path:
    cat /etc/ansible/ansible.cfg library = /usr/lib/python2.7/site-packages/ansible/modules:/etc/ansible/playbooks/sensu-go-ansible/library

  2. Create yml file with check definition

---
- hosts: all
  tasks:
    - name: Create a new check
      sensu_go_check:
        state: present
        host: <hostname>
        protocol: https
        port: 8081
        password: <password>
        namespace: default
        subscriptions:
          - default
        name: check_root_disk
        command: /usr/lib64/nagios/plugins/check_disk -w 15 -c 10 -p "/"
        interval: 60
        validate_certs: no
  1. run ansible
    ansible-playbook -i hosts checks.yml

  2. get error

TASK [Create a new check] ***********************************************************************************************************************************
fatal: [172.22.155.230]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 172.22.155.230 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/maximni/.ansible/tmp/ansible-tmp-1558048408.29-233429134634977/AnsiballZ_sensu_go_check.py\", line 113, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/maximni/.ansible/tmp/ansible-tmp-1558048408.29-233429134634977/AnsiballZ_sensu_go_check.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/maximni/.ansible/tmp/ansible-tmp-1558048408.29-233429134634977/AnsiballZ_sensu_go_check.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_sensu_go_check_payload_jzafha/__main__.py\", line 489, in <module>\r\n  File \"/tmp/ansible_sensu_go_check_payload_jzafha/__main__.py\", line 485, in main\r\n  File \"/tmp/ansible_sensu_go_check_payload_jzafha/__main__.py\", line 444, in run_module\r\n  File \"/tmp/ansible_sensu_go_check_payload_jzafha/__main__.py\", line 322, in auth\r\nTypeError: 'NoneType' object has no attribute '__getitem__'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Hey @maximnik,

Thanks for filing an issue! I just did some more updates to the module (trying to get it feature/bug complete in my free time). You're config looks correct off hand.

Can you try this again with the latest on master?

Oh, um, your port config might be wrong, unless you changed it, apid runs on 8080 with just http. I see you used 8081 which

8081 (WS/WSS) Agent API: Required for all Sensu agents connecting to a Sensu backend

I should make the module defensive here as well, which I can look into.

Yep! I thinks that's it, I'm able to repro the failure:

❯ pipenv run python  ./library/sensu_go_check.py ~/Downloads/test_delete_bad_port_sensu_go_check.json
Traceback (most recent call last):
  File "./library/sensu_go_check.py", line 538, in <module>
    main()
  File "./library/sensu_go_check.py", line 534, in main
    run_module()
  File "./library/sensu_go_check.py", line 478, in run_module
    module.auth()
  File "./library/sensu_go_check.py", line 355, in auth
    self.headers.update({'Authorization': 'Bearer ' + response['access_token']})
TypeError: 'NoneType' object has no attribute '__getitem__'

Used this which is close to your config:

{
    "ANSIBLE_MODULE_ARGS": {
        "state": "absent",
	"interval": 60,
	"name": "check_failed",
	"host": "localhost",
	"port": 8081,
	"protocol": "https",
	"validate_certs": false,
	"password": "PASSWORDHERE"
    }
}

I'll make the module not stack trace like it is, but, try dropping port, protocol, and validate_certs and I think the defaults will work for you.

Let me know!

#99 should handle this failure, thanks again for reporting!

Please let me know if the above helped or if you're hitting any other issues, more than happy to help debug.