There are 2 errors but one is related to the module and the other is imho a problem of the API.
The error with the module is again that "body" is used but not defined. (If I put that in a loop over "play_hosts" then it works)
The general problem is that first hosts get "service discovered" and then there is a 500 error or so..
TASK [cmk_host_registration : Add/update/remove host] ****************************************************************
changed: [Host1 -> localhost]
changed: [Host2 -> localhost]
changed: [Host3 -> localhost]
changed: [Host4 -> localhost]
changed: [Host5 -> localhost]
RUNNING HANDLER [cmk_host_registration : service discovery] **********************************************************
changed: [Host4 -> localhost]
changed: [Host1 -> localhost]
changed: [Host3 -> localhost]
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'body'
fatal: [Host5 -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/Users/mathias.buresch/.ansible/tmp/ansible-tmp-1653903276.5778098-98682-264119765984817/AnsiballZ_cmk_discovery.py\", line 107, in <module>\n _ansiballz_main()\n File \"/Users/mathias.buresch/.ansible/tmp/ansible-tmp-1653903276.5778098-98682-264119765984817/AnsiballZ_cmk_discovery.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/Users/mathias.buresch/.ansible/tmp/ansible-tmp-1653903276.5778098-98682-264119765984817/AnsiballZ_cmk_discovery.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible.modules.cmk_discovery', init_globals=dict(_module_fqn='ansible.modules.cmk_discovery', _modlib_path=modlib_path),\n File \"/usr/local/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 209, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 96, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n exec(code, run_globals)\n File \"/var/folders/6_/qjhhb7fn13g6r839l49tjg58s_y621/T/ansible_cmk_discovery_payload_vulpzc1w/ansible_cmk_discovery_payload.zip/ansible/modules/cmk_discovery.py\", line 170, in <module>\n File \"/var/folders/6_/qjhhb7fn13g6r839l49tjg58s_y621/T/ansible_cmk_discovery_payload_vulpzc1w/ansible_cmk_discovery_payload.zip/ansible/modules/cmk_discovery.py\", line 166, in main\n File \"/var/folders/6_/qjhhb7fn13g6r839l49tjg58s_y621/T/ansible_cmk_discovery_payload_vulpzc1w/ansible_cmk_discovery_payload.zip/ansible/modules/cmk_discovery.py\", line 147, in run_module\nKeyError: 'body'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'body'
$ ansible --version
ansible [core 2.12.5]
$ ansible-galaxy collection list
Tested with 0.3.2 and "devel"
- name: "Add/update/remove host"
# tribe29.checkmk.host:
cmk_host:
server_url: "https://{{ cmk_central }}/"
site: "{{ cmk_central_site }}"
automation_user: "{{ cmk_site_user }}"
automation_secret: "{{ cmk_site_password }}"
host_name: "{{ cmk_host_name | default(host_name) }}"
attributes:
"{{ cmk_host_attributes | default(omit) }}"
folder: "{{ host_folder }}"
state: "{{ cmk_host_state | default('present') }}"
delegate_to: localhost
become: no
notify:
- service discovery
- activate changes
- name: service discovery
# tribe29.checkmk.discovery:
cmk_discovery:
server_url: "https://{{ cmk_central }}/"
site: "{{ cmk_central_site }}"
automation_user: "{{ cmk_site_user }}"
automation_secret: "{{ cmk_site_password }}"
host_name: "{{ host_name }}"
# host_name: "{{ hostvars[item]['cmk_host_name'] | default(hostvars[item]['host_name']) }}"
# state: "fix_all"
state: "new"
delegate_to: localhost
# loop: "{{ play_hosts }}"
## loop_control:
## pause: 3
# run_once: true
become: no