Getting started

Example inventory

You can install Check_MK agent on a host by adding it to the [debops_services_checkmk_agent host group in your Ansible inventory:

[debops_services_checkmk_agent]
hostname

Example playbook

Here's an example playbook that uses the debops-contrib.checkmk_agent role:

---

- name: Manage Check_MK agent
  hosts:  [ 'debops_service_checkmk_agent' ]
  become: True

  environment: '{{ inventory__environment | d({})
                   | combine(inventory__group_environment | d({}))
                   | combine(inventory__host_environment  | d({})) }}'

  roles:

    - role: debops-contrib.checkmk_agent/env
      tags: [ 'role::checkmk_agent', 'role::checkmk_agent:env', 'role::mariadb' ]

    - role: debops.apt_preferences
      tags: [ 'role::apt_preferences' ]
      apt_preferences__dependent_list:
        - '{{ checkmk_agent__apt_preferences__dependent_list }}'

    - role: debops.etc_services
      tags: [ 'role::etc_services' ]
      etc_services__dependent_list:
        - '{{ checkmk_agent__etc_services__dependent_list }}'
      when: ('xinetd' in checkmk_agent__type)

    - role: debops.ferm
      tags: [ 'role::ferm' ]
      ferm__dependent_rules:
        - '{{ checkmk_agent__ferm__dependent_rules }}'

    - role: debops.tcpwrappers
      tags: [ 'role::tcpwrappers' ]
      tcpwrappers__dependent_allow:
        - '{{ checkmk_agent__tcpwrappers__dependent_allow }}'

    - role: debops.authorized_keys
      tags: [ 'role::authorized_keys' ]
      authorized_keys__dependent_list:
        - '{{ checkmk_agent__authorized_keys__dependent_list }}'

    - role: debops.mariadb
      tags: [ 'role::mariadb' ]
      mariadb__dependent_users:
        - '{{ checkmk_agent__mariadb__dependent_users }}'
      when: ("mk_mysql" in checkmk_agent__combined_plugins)

    - role: debops-contrib.checkmk_agent
      tags: [ 'role::checkmk_agent' ]

The playbook is shipped with this role under docs/playbooks/checkmk_agent.yml from which you can symlink it to your playbook directory.

As you can see in this example playbook, the role makes use of a number of other roles to setup it’s environment. Some of these dependency roles are only needed when services are detected. This is true for the debops.mariadb role which is used to manage a database user used to monitor the DBMS and databases by an automatically setup and configured agent plugin. To ensure that checkmk_agent__combined_plugins is valid in the context of other roles (in the same playbook) this variable is based on Ansible facts which are setup by the debops-contrib.checkmk_agent/env role prior to other dependency roles being called. For more details, refer to checkmk_agent__plugin_autodetect.

Ansible tags

You can use Ansible --tags or --skip-tags parameters to limit what tasks are performed during Ansible run. This can be used after a host was first configured to speed up playbook execution, when you are sure that most of the configuration is already in the desired state.

Available role tags:

role::checkmk_agent:env
Environment role tag, should be used in the playbook to execute a special environment role contained in the main role. The environment role prepares the environment for other dependency roles to work correctly.
role::checkmk_agent
Main role tag, should be used in the playbook to execute all of the role tasks as well as role dependencies.
role::checkmk_agent:pkgs
Tasks related to system package management like installing or removing packages.
role::checkmk_agent:plugins
Run tasks related to Check_MK agent plugin configuration.
role::checkmk_agent:plugins:get
Run tasks related to Check_MK agent plugin retrieval.