Is there a faster way to discover new services periodicly?

CMK version: 2.2.0p21
OS version: Ubuntu 22.04

I’m using the ansible galaxy collection and currently this is my playbook that runs against a group of hosts. (They were added with from a previous task) Is there a better way to run discovery on all hosts, without taking over 6s per host (Currently takes around 30 minutes for all and I still have hosts to add to.) I’ve tried using the bulk option as well (as seen), but it doesn’t look like to work any better, still takes 6s per host.
Any advice would be apprciated.

  tasks:
#Discover services on checkmk_hosts.
    - name: Discovered services, update labels and remove vanished services on hosts checkmk_hosts"
      checkmk.general.discovery:
        server_url: "{{ checkmk_var_server_url }}"
        site: "{{ checkmk_var_site }}"
        automation_user: "{{ checkmk_var_automation_user }}"
        automation_secret: "{{ checkmk_var_automation_secret }}"
        host_name: "{{ item.name }}"
        state: "fix_all"
        bulk_size: 10
      loop: "{{ checkmk_hosts }}"

What you show is not the bulk mode. With the loop statement you run the task once for each host. bulk_size doesn’t make sense in that case.

For the bulk mode you need to replace the host_name attribute (for one single host) with the hosts attribute (which is a list of hosts) and then drop the loop statement. Only then the bulk_size makes sense.

Try

- name: Discovered services, update labels and remove vanished services on hosts checkmk_hosts"
  checkmk.general.discovery:
    server_url: "{{ checkmk_var_server_url }}"
    site: "{{ checkmk_var_site }}"
    automation_user: "{{ checkmk_var_automation_user }}"
    automation_secret: "{{ checkmk_var_automation_secret }}"
    hosts: "{{ checkmk_hosts }}"
    state: "fix_all"
    bulk_size: 10

(Disclaimer: I haven’t tried this because I don’t have this ansible collection installed. I just read the docs and am a bit familiar with Ansible. Might be that you need to write the line hosts: "{{ checkmk_hosts }}" a bit differently to just pick their names.)

2 Likes

That is what I initially tried, but the idea behind the item.name is that the hosts have additional attributes and I want to specify only the name and abstract from the others . Example as below :

#Dummy Hosts
  - name: "cloud"
    alias: "Cloud Folder"
    ip: "127.0.0.1"
    folder: "/dummy_hosts"
  - name: "on_prem"
    alias: "On Premise Folder"
    ip: "127.0.0.1"
    folder: "/dummy_hosts"

Currently if I change this it would fail the task.
Do you think there is a better way or should I create a separate inventory?

I’m not 100% sure but try this:

hosts: "{{ checkmk_hosts | map(attribute='name') | list }}"
4 Likes

Yes, that is working perfectly as intended.
Thanks a lot!

1 Like