Checkmk / ansible-collection-checkmk.general

The official Checkmk Ansible collection - brought to you by the Checkmk company.
https://galaxy.ansible.com/checkmk/general
GNU General Public License v3.0
123 stars 56 forks source link

[FEED] Catch error for non-running site #25

Closed robin-checkmk closed 2 years ago

robin-checkmk commented 2 years ago

Verify first that your issue is not already reported here. Where possible also test if the latest release and main branch are affected too. Complete all sections as described!

Describe the bug

When running against a non-started site, e.g. the folder module fails with an arbitrary error message.

Component Name

folder

But affects all modules, probably.

Ansible Version

$ ansible --version
ansible [core 2.12.1]
  config file = None
  configured module search path = ['/home/robin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/robin/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/robin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/robin/.local/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 3.0.3
  libyaml = True

Checkmk Version

2.0.0p21 (CEE)

Collection Version

$ ansible-galaxy collection list
# /home/robin/.local/lib/python3.8/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0  
ansible.netcommon             2.5.0  
ansible.posix                 1.3.0  
ansible.utils                 2.4.3  
ansible.windows               1.9.0  
arista.eos                    3.1.0  
awx.awx                       19.4.0 
azure.azcollection            1.10.0 
check_point.mgmt              2.2.0  
chocolatey.chocolatey         1.1.0  
cisco.aci                     2.1.0  
cisco.asa                     2.1.0  
cisco.intersight              1.0.18 
cisco.ios                     2.6.0  
cisco.iosxr                   2.6.0  
cisco.ise                     1.2.1  
cisco.meraki                  2.5.0  
cisco.mso                     1.3.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.8.2  
cisco.ucs                     1.6.0  
cloud.common                  2.1.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 2.1.0  
community.azure               1.1.0  
community.ciscosmb            1.0.4  
community.crypto              2.0.2  
community.digitalocean        1.14.0 
community.dns                 2.0.3  
community.docker              2.0.2  
community.fortios             1.0.0  
community.general             4.2.0  
community.google              1.0.0  
community.grafana             1.3.0  
community.hashi_vault         2.1.0  
community.hrobot              1.2.1  
community.kubernetes          2.0.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.2  
community.mongodb             1.3.2  
community.mysql               2.3.2  
community.network             3.0.0  
community.okd                 2.1.0  
community.postgresql          1.6.0  
community.proxysql            1.3.0  
community.rabbitmq            1.1.0  
community.routeros            2.0.0  
community.skydive             1.0.0  
community.sops                1.2.0  
community.vmware              1.17.0 
community.windows             1.9.0  
community.zabbix              1.5.1  
containers.podman             1.9.0  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.13 
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            4.3.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.13.0 
fortinet.fortimanager         2.1.4  
fortinet.fortios              2.1.3  
frr.frr                       1.0.3  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.4  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.2.1  
inspur.sm                     1.3.0  
junipernetworks.junos         2.8.0  
kubernetes.core               2.2.2  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0 
netapp.ontap                  21.14.1
netapp.storagegrid            21.9.0 
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.4.0  
ngine_io.cloudstack           2.2.2  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.5.3  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   1.6.6  
purestorage.flasharray        1.11.0 
purestorage.flashblade        1.9.0  
sensu.sensu_go                1.12.1 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.26.0 
theforeman.foreman            2.2.0  
vyos.vyos                     2.6.0  
wti.remote                    1.0.3  

# /home/robin/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
amazon.aws        3.0.0  
community.docker  2.0.1  
community.general 4.2.0  
kubernetes.core   2.2.2  
tribe29.checkmk   0.1.0 

Environment

Ubuntu 20.04

To Reproduce Steps to reproduce the behavior:

  1. Install the collection.
  2. Run any module against a site, which is stopped.
  3. See the error.

Expected behavior

A clear error message is printed, that the site is not running.

Actual behavior

The module prints an arbitrary error message.

Screenshots

Additional context

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'body' referenced before assignment
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.tribe29.checkmk.plugins.modules.folder', init_globals=dict(_module_fqn='ansible_collections.tribe29.checkmk.plugins.modules.folder', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 306, in <module>\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 302, in main\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 270, in run_module\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 156, in get_current_folder_state\nUnboundLocalError: local variable 'body' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
robin-checkmk commented 2 years ago

@lgetwan what do you think? Is there any value in trying to improve the modules in a way that the error message becomes more clear, or would you say the error messages we get are good enough? I tend to lean towards leaving it as it is, because adding some kind of checking would add a lot of overhead to each module, while probably not providing that much more value. We can only make sure the error message we get anyway is as good as possible.

lgetwan commented 2 years ago

Sounds reasonable to me. Let's leave it.