Create Admin Automation/User using ansible collection

CMK version:
OMD - Open Monitoring Distribution Version 2.2.0p22.cre

OS version:
Ubuntu Jammy-Jellyfish

Error message:

fatal: [checkmk.example.edu]: FAILED! => {“changed”: false, “msg”: “unknown url type: ‘checkmk.example.edu/monitor/check_mk/api/1.0//objects/user_config/troubleshooting’”, “status”: -1, “url”: “checkmk.example.edu/monitor/check_mk/api/1.0//objects/user_config/troubleshooting”}

Hello,

We are attempting to use the Checkmk/ansible-collection-checkmk.general to automatically add hosts.

We are able to successfully create a site with a cmkadmin + password. We are also able to create an automation user successfully but the automation user is unable to authenticate or do much else.

Our hope was the automation user as suggested in the documentation would be able to add agents to monitor. Our variables look like so.

---
server_url: "checkmk.example.edu"
site: "monitor"
automation_user: "ansible_automation"
automation_secret: "{{ vault_ansible_automation_secret }}"

checkmk_folders:
  - path: /test
    title: Test
  - path: /foo
    title: Foo
  - path: /bar
    title: Bar

# Agent role
checkmk_agent_version: "2.2.0p22"
checkmk_agent_edition: cre
checkmk_agent_protocol: http
checkmk_agent_server: "{{ server_url }}"
checkmk_agent_site: monitor
checkmk_agent_user: "{{ automation_user | default('automation') }}"
checkmk_agent_pass: "{{ automation_secret }}"
checkmk_agent_update: 'true'
checkmk_agent_tls: 'true'
checkmk_agent_configure_firewall: 'false'
checkmk_agent_prep_legacy: 'false'
checkmk_agent_add_host: 'true'
checkmk_agent_discover: 'false'
checkmk_agent_delegate_api_calls: localhost

# Server Role
checkmk_server_edition: cre
checkmk_server_version: 2.2.0p22
checkmk_server_verify_setup: 'true'
checkmk_server_configure_firewall: 'false'


checkmk_server_sites:
  - name: monitor
    version: "{{ checkmk_server_version }}"
    state: started
    admin_pw: "{{ vault_admin_pw }}"
    update_conflict_resolution: install
    omd_auto_restart: 'false'
    omd_config:
      - var: LIVESTATUS_TCP
        value: "on"
      - var: LIVESTATUS_TCP_PORT
        value: "6557"

and our playbook that points to the variables above look like this

---
- name: build the checkmk site
  hosts: checkmk.example.edu
  remote_user: systems
  become: true
  vars_files:
    - ../group_vars/checkmk/{{ runtime_env | default('staging') }}.yml
    - ../group_vars/checkmk/vault.yml
  tasks:

    - name: Import checkmk role
      ansible.builtin.import_role:
        name: checkmk.general.server

    - name: "Pause."
      ansible.builtin.pause:
        prompt: |
          "Press <Enter> to continue."

- name: build agent connections on a checkmk site
  hosts: sandboxes
  remote_user: systems
  become: true
  # gather_facts: false
  vars_files:
    - ../group_vars/checkmk/{{ runtime_env | default('staging') }}.yml
    - ../group_vars/checkmk/vault.yml
  tasks:
    - name: Activate changes on checkmk site - Showcase no changes.
      checkmk.general.activation:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        force_foreign_changes: true
        sites:
          - "{{ site }}"
      delegate_to: localhost
      become: true
      become_user: monitor
      run_once: true

    - name: Create team folders. 
      checkmk.general.folder:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        path: "{{ item.path }}"
        title: "{{ item.title }}"
        state: "present"
      delegate_to: localhost
      run_once: true
      loop: "{{ checkmk_folders }}"

    - name: Create a checkmk host.
      checkmk.general.host:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        host_name: "{{ inventory_hostname }}"
        folder: "{{ checkmk_folder_path }}"
        attributes:
          site: "{{ site }}"
          ipaddress: 127.0.0.1
        state: "present"
      delegate_to: localhost

    - name: Discover services on host.
      checkmk.general.discovery:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        host_name: "{{ inventory_hostname }}"
        state: "fix_all"
      delegate_to: localhost

    - name: Activate changes on site - Showcase creation of hosts and folders. # checkmk doesn't automatically accept changes
      checkmk.general.activation:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        force_foreign_changes: true
        sites:
          - "{{ site }}"
      delegate_to: localhost
      run_once: true

We do have a workaround whereby manually creating an administrative user, allows the playbook to work just fine. We are happy to work with this as the solution unless someone points us to anything we are not understanding.

That is wrong. Use the following variables instead (as the README says):

checkmk_agent_server_protocol: http
checkmk_agent_server: localhost

I cannot say, how and why your workaround would work, but the error you posted clearly is a result of the faulty use of server_url.