Agent installation moves existing host to root folder

I have this simple ansible playbook to install the CheckMK agent on linux hosts, create the host in CheckMK and register automatically. It works all fine, but existing hosts are moved to the root folder.

I usually just move the hosts in CheckMK directly as the environment is very heterogenic.

Is there a way around this except defining the folder path in the ansible inventory?

---
- hosts: all
  become: true
  roles:
     - role: checkmk.general.agent
       vars:
           checkmk_agent_edition: cee
           checkmk_agent_server: checkmk
           checkmk_agent_server_ips: [10.x.x.x]
           checkmk_agent_site: site1
           checkmk_agent_server_protocol: https
           checkmk_agent_user: user
           checkmk_agent_secret: secret
           checkmk_agent_add_host: true
           checkmk_agent_discover: true
           checkmk_agent_update: true
           checkmk_agent_tls: true
           checkmk_agent_prep_legacy: true
           checkmk_agent_configure_firewall: true
           checkmk_agent_host_attributes:
            alias: "{{ hostvars[inventory_hostname]['human_description'] | default(omit) }}"

Ansible is a desired state configuration tool, so it ensures a certain state.
When using the agent role, it passes on a folder to the host module when the host is added to Checkmk. As it needs a folder to put the host in, this is not optional.

What you can do is this: Run the agent role only with the variable checkmk_agent_add_host: true once and set the variable to false for all subsequent runs. That way the role will not touch the host object in Checkmk anymore.

Or manage the folder with Checkmk entirely. Your choice. :slight_smile:

1 Like

Yes, this makes sense, thank you!

Interestingly this also seems to cause some problems when specifying host attributes (alias in my case):

4:22:31 PM
TASK [checkmk.general.agent : Linux: Create host on server.] *******************
4:22:34 PM
fatal: [hostname.example.com -> localhost]: FAILED! => {"changed": false, "failed_when_result": true, "msg": "ERROR: The folder parameter is different from the folder in which the host is located, while other parameters are also specified!\n                     If you want to move the host to a specific folder, please omit the other parameters:                     'attributes', 'update_attributes' and 'remove_attributes'."}
1 Like

That is actually a safeguard against exactly the issue with “randomly moving hosts”. :slight_smile:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.