Giter Club home page Giter Club logo

ansible-collection-checkmk.general's Introduction

Checkmk - Your complete IT monitoring solution

PR-CI status

Checkmk is available in several editions. The Checkmk Raw Edition is free and 100% open-source. The Checkmk Enterprise Edition includes several additional features and professional support from the authors, billed annually. A demo version is freely available for testing the Enterprise Edition.

Checkmk can be installed on Linux servers via DEB and RPM packages found on our downloads page. The Enterprise Edition is also available as a virtual or physical appliance. The following short installation guides show how you can easily set up Checkmk and begin monitoring.

Please visit our website for more details.

Getting started

Please have a look at the beginners guide on how to get started with Checkmk.

Want to contribute?

Nice! Before contributing please check out our contribution guidelines.

Building on your own packages

It is highly recommended to use the prebuilt Checkmk packages we provide. But if you really want to build your own packages, you either need to download the source packages from our website or check out the Git repository.

We're building the Checkmk packages within specific docker images for the different distros. Please find the Dockerfiles under buildscripts/infrastructure/build-nodes/ in order to get an idea what's needed to build it locally. However, keep in mind that those Dockerfiles are heavily relying on our infrastructure and won't build from scratch on your machine.

If you have the dependencies in place, you can either create RPM or DEB packages, depending on your Linux distribution.

To build an RPM:

make rpm

To create a DEB package:

DEBFULLNAME="Mr. Buildmaster" DEBEMAIL="[email protected]" make deb

Don't forget to insert your name and mail address. As a result you should find packages of the form check-mk-[edition]-[version].[deb|rpm] in your current directory.

ansible-collection-checkmk.general's People

Contributors

darrindg91 avatar dependabot[bot] avatar diademiemi avatar englertor avatar flybyray avatar godspeed-you avatar hb9hnt avatar janpetto avatar jzuellig avatar kain88-de avatar lgetwan avatar lupusanimus avatar mareise avatar max-checkmk avatar meni2029 avatar mik3yz avatar msekania avatar mto79 avatar muehlings avatar mueller-ma avatar neffs avatar nico-checkmk avatar ogaida avatar robin-checkmk avatar simonhir avatar sscmh avatar synss avatar thorian93 avatar tonk avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-collection-checkmk.general's Issues

[BUG] rule module does not respect parameter folder

rule module does not respect parameter folder

module rule does not respect the parameter folder, only the parameters conditions, properties, value_raw.

It does not take into account that folder might be also different.

As a result one cannot assign the rule with the same conditions, properties, value_raw to two different folders.

With REST API it is possible!

snippet from the rule module

def get_existing_rule(module, base_url, headers, ruleset, rule):
    # Get rules in ruleset
    rules = get_rules_in_ruleset(module, base_url, headers, ruleset)
    if rules is not None:
        # Loop through all rules
        for r in rules.get("value"):
            # Check if conditions, properties and values are the same
            if (
                sorted(r["extensions"]["conditions"]) == sorted(rule["conditions"])
                and sorted(r["extensions"]["properties"]) == sorted(rule["properties"])
                and sorted(r["extensions"]["value_raw"]) == sorted(rule["value_raw"])
            ):
                # If they are the same, return the ID
                return r["id"]
    return None

There is no check for r["extensions"]["folder"]

Component Name

rule

Ansible Version

any

Checkmk Version

any

Collection Version

any with rule module

Environment

To Reproduce

Example, only folder is different

- name: "Create a rule in checkgroup_parameters:memory_percentage_used for production/proxies"
  tribe29.checkmk.rule:
    server_url: "http://localhost/"
    site: "my_site"
    automation_user: "automation"
    automation_secret: "$SECRET"
    ruleset: "checkgroup_parameters:memory_percentage_used"
    rule:
        folder: "/production/proxies"
        conditions: {
            "host_labels": [],
            "host_tags": [],
            "service_labels": []
        }
        properties: {
            "comment": "Warning at 80%\nCritical at 90%\n",
            "description": "Allow higher memory usage",
            "disabled": false,
            "documentation_url": ""
        }
        value_raw: "{'levels': (80.0, 90.0)}"
    state: "present"

- name: "Create a rule in checkgroup_parameters:memory_percentage_used for stging/proxies"
  tribe29.checkmk.rule:
    server_url: "http://localhost/"
    site: "my_site"
    automation_user: "automation"
    automation_secret: "$SECRET"
    ruleset: "checkgroup_parameters:memory_percentage_used"
    rule:
        folder: "/staging/proxies"
        conditions: {
            "host_labels": [],
            "host_tags": [],
            "service_labels": []
        }
        properties: {
            "comment": "Warning at 80%\nCritical at 90%\n",
            "description": "Allow higher memory usage",
            "disabled": false,
            "documentation_url": ""
        }
        value_raw: "{'levels': (80.0, 90.0)}"
    state: "present"

Expected behavior

Both should be created.

Actual behavior

The second one is skipped

Screenshots

Additional context

[FEED] consistent solution in host.py

Concerning the nasty host.py bug. Which as I see is now fixed with explicit call to "normalize_folder" function
line 299

current_folder = normalize_folder(current_folder)

actually, small change in line 140

        current_folder = "%s" % extensions.get("folder", "/")

instead of

        current_folder = "%s" % extensions.get("folder", "")

default folder should be “/” and not “”, might be more consistent

thanks, Michael

Add SELinux status detection [BUG]

Describe the bug
If selinux is disabled the role "tribe29.checkmk.server" to install check_mk and create a site failed with:

"msg": "SELinux is disabled on this host."

Component Name
roles/server/tasks/RedHat.yml with task name:

- name: "Enable httpd can network connect selinux boolean."

Expected behavior

Role does not fail, when selinux is disabled. Task could be improved with

when: ansible_facts.selinux.status == 'enabled'

[BUG] Discovery got same problem with body variable

Describe the bug

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'

Component Name

discovery

Ansible Version

$ ansible --version
ansible [core 2.12.5]

Checkmk Version

2.1.0 (CEE)

Collection Version

$ ansible-galaxy collection list
Tested with 0.3.2 and "devel"

Environment

To Reproduce
Steps to reproduce the behavior:

- 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

Expected behavior

  1. There should be a correct error message
  2. API should not throw an error

Actual behavior

Screenshots

Additional context

Improve HTTP 500 handling in discovery module

Describe the bug

When doing a service discovery on a host, that has no proper DNS-resolvable name or IP address set, the discovery module fails with a 500 HTTP code and without a human readable message.

Component Name

discovery

Ansible Version

$ ansible --version
ansible [core 2.12.4]
  config file = /vagrant/ansible.cfg
  configured module search path = ['/vagrant/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Checkmk Version

2.0.0p23 (CRE)
2.1.0b5 (CRE)

Collection Version

$ ansible-galaxy collection list
Collection      Version
--------------- -------
tribe29.checkmk 0.2.0

Environment

To Reproduce
Steps to reproduce the behavior:

  1. Add a host with an improper name (e.g. 'testhost.tld')
  2. Run the discovery module (state does not matter)
  3. See the generic error message

Expected behavior

The module should print the detail message from the response body:
image

Actual behavior

A generic error message is displayed.

Additional context

In 3aa5c14 a quick fix was introduced, but it needs better handling.
This issue, once fixed, also closes #33.

[BUG] Rule Module not correct?

Hi, we have tried the rule module created by @diademiemi . First of all thanks for that work! But we have tested and debugged it and we aren't sure if that is working correctly. Maybe we are missing a point.

If you get for example r["extensions"]["conditions"] it only got the keys but not the values for comparing.
Also if the value_raw is sorted it not really sorts the keys, instead it sorts every character. Maybe the last is working anyway kinda but the other are not working.

We have debugged it with adjusting the following function (reason for debug was to find out if the API output was changed):

def get_existing_rule(module, base_url, headers, ruleset, rule):
    # Get rules in ruleset
    rules = get_rules_in_ruleset(module, base_url, headers, ruleset)
    a_list = []
    b_list = []
    if rules is not None:
        # Loop through all rules
        for r in rules.get("value"):
    #        rule_exist = sorted(r)
    #        rule_defined = sorted(rule["properties"])
    #        exit_failed(module, "Rule_exist: %s, Rule_defined: %s , " % (rule_exist, rule_defined),)
            foo = sorted(r["extensions"]["conditions"])
            bar = sorted(rule["conditions"])
            a_list.append(foo)
            b_list.append(bar)
            # Check if conditions, properties and values are the same
            if (
                sorted(r["extensions"]["conditions"]) == sorted(rule["conditions"])
    #            and sorted(r["extensions"]["properties"]) == sorted(rule["properties"])
                and sorted(r["extensions"]["value_raw"]) == sorted(rule["value_raw"])
            ):
                # If they are the same, return the ID
                return r["id"]
        exit_failed(module, "Rule_exist: %s, Rule_defined: %s , " % (a_list, b_list),)
    return None

PS: I also wonder why the json output was choosed with ().. This is not really the standard way like other tools how jq could read it by default.

[FEED] Close similarity between modules

Hi @robin-tribe29,

somehow this close similarity of contact and host groups does not give me a rest.
I have also checked and service group rest API interface is also quite similar.
I do not know, whether this similarity will also stay in the future, but in case, I have a group module written that combines all this three group management in one (including test suite).

https://github.com/msekania/ansible-collection-tribe29.checkmk/tree/feature-groups

In current version, there is a group_type field which takes one of ["contact", "host", "service"] values, and the rest is provided either by group_name (instead of host_group_name, contact_group_name) and title or list of dict-s named 'groups' (instead of host_group, contact_group) with name and title entries.
I can also add a backward compatibility features.

Alternatively, I can rewrite the module so that group_type field is removed and choice is made by providing:

  • host_group_name or host_groups;
  • contact_group_name or contact_groups;
  • service_group_name or service_groups;

Should I make an another pull request?
We can decide then how to proceed.

Best,
Michael

Originally posted by @msekania in #168 (comment)

Porting Checklist

  • activation
  • contact_group
  • discovery
  • downtime
  • folder
  • host_group
  • host
  • rule
  • service_group
  • tag_group
  • user

[FEED] Support CME

In many API endpoints, the CME has "customer" as a mandatory field. We have to take care of this.

[BUG] idempotency not working for hosts and folders

Describe the bug
When I am trying to create a folder without trailing slash e.g.: path: "/folder" the run will say "ok", but the folder is not being created. If I use trailing slash e.g. path: "/folder/", the folder is being created.
But in the next run, this exact same task is going to fail with error:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Path already exists\", \"status\": 400, \"detail\": \"The path \\'/folder\\' already exists.\"}', "}
This can be worked around by removing the trailing slash in the code.

Creating hosts does not seem to be idempotent, as the host is being created at the first run, but subsequent runs are throwing errors:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Invalid move action\", \"status\": 400, \"detail\": \"The host is already part of the specified target folder\"}', "}
Component Name
folder
host

Ansible Version

ansible --version
ansible [core 2.13.1]

Checkmk Version

2.1.0p2 (CME)

Collection Version
0.5.0

Environment
python 3.8.2

To Reproduce
Run the same playbook multiple times:

---
- hosts: localhost
  gather_facts: 'no'
  
  collections:
    - tribe29.checkmk

  tasks:
    - name: "Create folder"
      folder:
        server_url: "https://checkmk"
        site: "mysite"
        automation_user: "automation"
        automation_secret: "secret"
        path: "/folder"
        title: "Folder"
        state: "present"
      run_once: 'true'
      delegate_to: localhost
    - name: "Create a host."
      tribe29.checkmk.host:
        server_url: "https://checkmk/"
        site: "mysite"
        automation_user: "automation"
        automation_secret: "secret"
        host_name: "test_host"
        folder: "/"
        state: "present"
      delegate_to: localhost
      run_once: 'true'

Expected behavior
Folder and Host being created, subsequent runs being "ok" in terms of ansible idempotency

Actual behavior
subsequent runs failing

[BUG] Improper handling of automatic update registration

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

Component Name

role agent

Ansible Version

$ ansible --version

Checkmk Version

2.1.0p10.cee

Collection Version

$ ansible-galaxy collection list

Environment

To Reproduce
Steps to reproduce the behavior:

  1. Run the agent role against CEE site.
  2. If the agent package does not contain the automatic updater, the registration task fails.

Expected behavior

The task should be skipped, or a warning should be printed.

Actual behavior

The role fails.

Screenshots

Additional context

[BUG] value_raw set to a variable

Describe the bug
I'm trying to set the value of value_raw to a variable instead of hardcoding it in the task, so I can reuse the same task for multiple rules. Unfortunately I get the error "Unsupported type. Field must be string". The same task with the value_raw explicitly set works fine. Seems to be an escaping issue, and I'm not 100% the issue is with the collection honestly.. but I'm banging my head on this so any help is appreciated.

Component Name
tribe29.checkmk.rule

Ansible Version

$ ansible --version
ansible 2.10.8
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]

Checkmk Version

Checkmk Raw Edition 2.1.0p13

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk   0.11.0

To Reproduce
Steps to reproduce the behavior:
Execute this task:

    - name: "Create a rule."
      tribe29.checkmk.rule:
        server_url: "{{ hostvars['checkmk'].checkmk_url }}"
        site: "{{checkmk_site}}"
        automation_user: "{{ hostvars['checkmk'].checkmk_user }}"
        automation_secret: "{{ hostvars['checkmk'].checkmk_secret }}"
        ruleset: "checkgroup_parameters:memory_percentage_used"
        rule:
            properties: {
                "comment": "Warning at 80%\nCritical at 90%\n",
                "description": "Allow higher memory usage",
                "disabled": false
            }
            value_raw: "{{ myvariable }}"
        state: "present"
      vars:
        - myvariable: "{'levels': (80.0, 90.0)}"

If I replace value_raw: "{{ myvariable }}" to value_raw: "{'levels': (80.0, 90.0)}" the task works fine.

Expected behavior
Rule to be created using the value in "myvariable"

Actual behavior
The following error is printed:

"msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Bad Request\", \"status\": 400, \"detail\": \"These fields have problems: value_raw\", \"fields\": {\"value_raw\": [\"Unsupported type. Field must be string.\"]}}', "

Additional context
I suspect the issue is caused by the curly bracket required by the API which make ansible interpret the variable's value as a dictionary instead of a string. But I couldn't find a way to escape that and make it works with the API.

[BUG] The role agent still uses automation_xxx variables instead of checkmk_agent_xxx

Describe the bug
The agent role mentions checkmk_agent_user and checkmk_agent_pass in README and defaults/main.yml,
but everywhere in code are still references to automation_user and automation_secret. If those 2 are not passed from outside, role reports error. The mentioned variables are not used anywhere outside defaults.yml which seems to be a bug.

Component Name
agent role for sure, server role not checked

Ansible Version
all versions

Checkmk Version
all versions

Collection Version
v0.5.0

Environment
not relevant

To Reproduce
Just include the role without specifying automation_user and automation_secret variables, but providing checkmk_agent_user and checkmk_agent_pass

Expected behavior
role uses checkmk_agent_* variables

Actual behavior
role uses automation_* variables

Screenshots

Additional context

[BUG] CFE not properly supported in roles

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

Component Name

role agent
role server?

Ansible Version

$ ansible --version

Checkmk Version

2.1.0p10.cfe

Collection Version

$ ansible-galaxy collection list

Environment

To Reproduce
Steps to reproduce the behavior:

  1. Set checkmk_edition to cfe.
  2. Run the agent role.
  3. Nothing happens, due to conditionals not respecting cfe.

Expected behavior

CFE should work.

Actual behavior

Screenshots

Additional context

[FEED] Use variable name in agent registration

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback
Use the checkmk_agent_host_name variable when registering agents in the agent role rather than inventory_hostname. This would allow users to override the variable i.e. inventory_hostname_short

Component Name
agent role registration

Ansible Version

  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Collection Version

Environment

Screenshots

Additional context

[BUG] Folder creation fails with trailing slash

Describe the bug

Trying to create a folder with a trailing slash lets the folder module fail.

Component Name

folder

Ansible Version

$ ansible --version
ansible [core 2.12.5]
  config file = /vagrant/ansible.cfg
  configured module search path = ['/vagrant/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Checkmk Version

2.0.0p23 (CRE)

Collection Version

$ ansible-galaxy collection list
# /home/vagrant/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
tribe29.checkmk 0.2.2 

Environment

Ubuntu 20.04
Python 3.8.10

To Reproduce
Steps to reproduce the behavior:

  1. Create a folder without a trailing slash
  2. Try to create the exact same folder again, but with a trailing slash now

Expected behavior

We get an OK state from Ansible, as the folder already exists.

Actual behavior

We get an error message and the task fails:

TASK [Create folders.] **********************************************************************************
failed: [test1.tld -> localhost] (item={'path': '/test/', 'title': 'Test'}) => {"ansible_loop_var": "item", "changed": false, "item": {"path": "/test/", "title": "Test"}, "msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Path already exists\", \"status\": 400, \"detail\": \"The path \\'\\\\/test\\' already exists.\"}', "}

Screenshots

Additional context

discovery and activation - generic error: "Error calling API"

When using discovery and/or activation modules, a generic error message is thrown:

{"changed": false, "http_code": -1, "msg": "Error calling API"}

The host module works as expected.

Ansible Version

$ .local/bin/ansible --version
ansible [core 2.12.4]
config file = None
configured module search path = ['/home/jonas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jonas/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/jonas/.ansible/collections:/usr/share/ansible/collections
executable location = .local/bin/ansible
python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
jinja version = 3.1.1
libyaml = True

Server Version

Checkmk Free Edition 2.1.0b4

Tasks to reproduce

- name: Add host to check_mk inventory. - works as expected
  delegate_to: localhost
  become: no
  tribe29.checkmk.host:
    server_url: '{{ check_mk_url }}'
    site: '{{ check_mk_site }}'
    automation_user: 'automation'
    automation_secret: 'super-secret-pass'
    host_name: '{{ inventory_hostname }}'
    folder: '/'
    state: 'present'

- name: Add newly discovered services. - throws generic error message
  delegate_to: localhost
  become: no
  tribe29.checkmk.discovery:
    server_url: '{{ check_mk_url }}'
    site: '{{ check_mk_site }}'
    automation_user: 'automation'
    automation_secret: 'super-secret-pass'
    host_name: '{{ inventory_hostname }}'
    state: 'new'

- name: Activate changes on all sites. - throws generic error message
  delegate_to: localhost
  become: no
  tribe29.checkmk.activation:
    server_url: '{{ check_mk_url }}'
    site: '{{ check_mk_site }}'
    automation_user: 'automation'
    automation_secret: 'super-secret-pass'

Collection Version

$ ansible-galaxy collection list tribe29.checkmk

# /home/jonas/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
tribe29.checkmk 0.1.0

first activation fails

Description

if i run my playbook, it creates the folder but the activation fails with a 414. Here is the playbook:

---
# ansible-playbook playbooks/og_create_folder.yml
- name: "create a folder"
  hosts: localhost
  gather_facts: 'no'
  vars_files:
    - ./vars/config.yml
  tasks:
  - name: "Create folders."
    folder:
      server_url: "{{ server_url }}"
      site: "{{ site }}"
      automation_user: "{{ automation_user }}"
      automation_secret: "{{ automation_secret }}"
      path: "/pis2"
      title: "pis2"
      state: "present"
      #state: "absent"
  - name: "Run activation module"
    activation:
      server_url: "{{ server_url }}"
      site: "{{ site }}"
      automation_user: "{{ automation_user }}"
      automation_secret: "{{ automation_secret }}"
      force_foreign_changes: true

the verbose output of the last task is:

TASK [Run activation module] ****************************************************************************************************************************
task path: /home/ogaida/ansible-collection-tribe29.checkmk/playbooks/og_create_folder.yml:19
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ogaida
<127.0.0.1> EXEC /bin/sh -c 'echo ~ogaida && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ogaida/.ansible/tmp `"&& mkdir "` echo /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509 `" && echo ansible-tmp-1647882812.068487-842528-97282019257509="` echo /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509 `" ) && sleep 0'
Including module_utils file ansible/__init__.py
Including module_utils file ansible/module_utils/__init__.py
Including module_utils file ansible/module_utils/basic.py
Including module_utils file ansible/module_utils/_text.py
Including module_utils file ansible/module_utils/common/_collections_compat.py
Including module_utils file ansible/module_utils/common/__init__.py
Including module_utils file ansible/module_utils/common/_json_compat.py
Including module_utils file ansible/module_utils/common/_utils.py
Including module_utils file ansible/module_utils/common/arg_spec.py
Including module_utils file ansible/module_utils/common/file.py
Including module_utils file ansible/module_utils/common/locale.py
Including module_utils file ansible/module_utils/common/parameters.py
Including module_utils file ansible/module_utils/common/collections.py
Including module_utils file ansible/module_utils/common/process.py
Including module_utils file ansible/module_utils/common/sys_info.py
Including module_utils file ansible/module_utils/common/text/converters.py
Including module_utils file ansible/module_utils/common/text/__init__.py
Including module_utils file ansible/module_utils/common/text/formatters.py
Including module_utils file ansible/module_utils/common/validation.py
Including module_utils file ansible/module_utils/common/warnings.py
Including module_utils file ansible/module_utils/compat/selectors.py
Including module_utils file ansible/module_utils/compat/__init__.py
Including module_utils file ansible/module_utils/compat/_selectors2.py
Including module_utils file ansible/module_utils/compat/selinux.py
Including module_utils file ansible/module_utils/distro/__init__.py
Including module_utils file ansible/module_utils/distro/_distro.py
Including module_utils file ansible/module_utils/errors.py
Including module_utils file ansible/module_utils/parsing/convert_bool.py
Including module_utils file ansible/module_utils/parsing/__init__.py
Including module_utils file ansible/module_utils/pycompat24.py
Including module_utils file ansible/module_utils/six/__init__.py
Including module_utils file ansible/module_utils/urls.py
Using module file /home/ogaida/ansible-collection-tribe29.checkmk/plugins/modules/activation.py
<127.0.0.1> PUT /home/ogaida/.ansible/tmp/ansible-local-8424638lh4qirn/tmpcnu7tipu TO /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509/AnsiballZ_activation.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509/ /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509/AnsiballZ_activation.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509/AnsiballZ_activation.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ogaida/.ansible/tmp/ansible-tmp-1647882812.068487-842528-97282019257509/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "http_code": 414,
    "invocation": {
        "module_args": {
            "automation_secret": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "automation_user": "automation",
            "force_foreign_changes": true,
            "server_url": "http://localhost:8080/",
            "site": "cmk",
            "sites": []
        }
    },
    "msg": "Error calling API"
}

PLAY RECAP **********************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

if i run the same playbook again, the activation works. my first guess was a timing problem. So i inserted a 5 seconds pause, but i does not help.

Component Name

Module: activation

Ansible Version

$ ansible --version
ansible [core 2.12.3]
  config file = /home/ogaida/ansible-collection-tribe29.checkmk/ansible.cfg
  configured module search path = ['/home/ogaida/ansible-collection-tribe29.checkmk/plugins/modules']
  ansible python module location = /home/ogaida/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/ogaida/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 2.11.3
  libyaml = True

Collection Version

$ ansible-galaxy collection list
# /usr/local/lib/python3.9/dist-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0  
ansible.netcommon             2.5.1  
ansible.posix                 1.3.0  
ansible.utils                 2.5.2  
ansible.windows               1.9.0  
arista.eos                    3.1.0  
awx.awx                       19.4.0 
azure.azcollection            1.11.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.2.0  
cisco.aci                     2.1.0  
cisco.asa                     2.1.0  
cisco.intersight              1.0.18 
cisco.ios                     2.8.0  
cisco.iosxr                   2.8.1  
cisco.ise                     1.2.1  
cisco.meraki                  2.6.0  
cisco.mso                     1.3.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.9.0  
cisco.ucs                     1.7.0  
cloud.common                  2.1.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 2.3.0  
community.azure               1.1.0  
community.ciscosmb            1.0.4  
community.crypto              2.2.3  
community.digitalocean        1.15.1 
community.dns                 2.0.8  
community.docker              2.2.1  
community.fortios             1.0.0  
community.general             4.6.0  
community.google              1.0.0  
community.grafana             1.3.3  
community.hashi_vault         2.3.0  
community.hrobot              1.2.2  
community.kubernetes          2.0.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.2  
community.mongodb             1.3.2  
community.mysql               2.3.5  
community.network             3.1.0  
community.okd                 2.1.0  
community.postgresql          1.7.1  
community.proxysql            1.3.1  
community.rabbitmq            1.1.0  
community.routeros            2.0.0  
community.skydive             1.0.0  
community.sops                1.2.0  
community.vmware              1.17.1 
community.windows             1.9.0  
community.zabbix              1.5.1  
containers.podman             1.9.1  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.13 
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            4.4.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.15.0 
fortinet.fortimanager         2.1.4  
fortinet.fortios              2.1.4  
frr.frr                       1.0.3  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.4  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.2.1  
inspur.sm                     1.3.0  
junipernetworks.junos         2.9.0  
kubernetes.core               2.2.3  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.15.0
netapp.elementsw              21.7.0 
netapp.ontap                  21.17.3
netapp.storagegrid            21.9.0 
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.6.0  
ngine_io.cloudstack           2.2.3  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.7.2  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   1.6.6  
purestorage.flasharray        1.12.1 
purestorage.flashblade        1.9.0  
sensu.sensu_go                1.13.0 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.27.1 
theforeman.foreman            2.2.0  
vyos.vyos                     2.8.0  
wti.remote                    1.0.3  

# /home/ogaida/.local/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0  
ansible.netcommon             2.5.1  
ansible.posix                 1.3.0  
ansible.utils                 2.5.2  
ansible.windows               1.9.0  
arista.eos                    3.1.0  
awx.awx                       19.4.0 
azure.azcollection            1.11.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.2.0  
cisco.aci                     2.1.0  
cisco.asa                     2.1.0  
cisco.intersight              1.0.18 
cisco.ios                     2.8.0  
cisco.iosxr                   2.8.1  
cisco.ise                     1.2.1  
cisco.meraki                  2.6.0  
cisco.mso                     1.3.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.9.0  
cisco.ucs                     1.7.0  
cloud.common                  2.1.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 2.3.0  
community.azure               1.1.0  
community.ciscosmb            1.0.4  
community.crypto              2.2.3  
community.digitalocean        1.15.1 
community.dns                 2.0.8  
community.docker              2.2.1  
community.fortios             1.0.0  
community.general             4.6.0  
community.google              1.0.0  
community.grafana             1.3.3  
community.hashi_vault         2.3.0  
community.hrobot              1.2.2  
community.kubernetes          2.0.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.2  
community.mongodb             1.3.2  
community.mysql               2.3.5  
community.network             3.1.0  
community.okd                 2.1.0  
community.postgresql          1.7.1  
community.proxysql            1.3.1  
community.rabbitmq            1.1.0  
community.routeros            2.0.0  
community.skydive             1.0.0  
community.sops                1.2.0  
community.vmware              1.17.1 
community.windows             1.9.0  
community.zabbix              1.5.1  
containers.podman             1.9.1  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.13 
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            4.4.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.15.0 
fortinet.fortimanager         2.1.4  
fortinet.fortios              2.1.4  
frr.frr                       1.0.3  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.4  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.2.1  
inspur.sm                     1.3.0  
junipernetworks.junos         2.9.0  
kubernetes.core               2.2.3  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.15.0
netapp.elementsw              21.7.0 
netapp.ontap                  21.17.3
netapp.storagegrid            21.9.0 
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.6.0  
ngine_io.cloudstack           2.2.3  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.7.2  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   1.6.6  
purestorage.flasharray        1.12.1 
purestorage.flashblade        1.9.0  
sensu.sensu_go                1.13.0 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.27.1 
theforeman.foreman            2.2.0  
vyos.vyos                     2.8.0  
wti.remote                    1.0.3  

Environment

$ uname -a
Linux pi4 5.10.63-v8+ #1488 SMP PREEMPT Thu Nov 18 16:16:16 GMT 2021 aarch64 GNU/Linux
$ cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ docker ps
CONTAINER ID   IMAGE                       COMMAND                  CREATED        STATUS                    PORTS                                                 NAMES
1d3c49f60f56   joeri2821/check-mk-raw-pi   "/docker-entrypoint.…"   2 months ago   Up 56 minutes (healthy)   6557/tcp, 0.0.0.0:8080->5000/tcp, :::8080->5000/tcp   monitoring

Checkmk 2.0.0p17

To Reproduce

run my playbook

Expected behavior

i expect no error by running this playbook

Actual behavior

the task with activation fails

Thanks in advance
BR
Oliver

[FEED] move hosts only on creation

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback

Hi there,

I'm using the collection to add hosts to my monitoring. I've got an issue with hosts that are already monitored.
Since the folder attribute isn't optional and has an default value of / the code on https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/devel/plugins/modules/host.py#L287-L289 will be executed:

        if current_folder != module.params["folder"]:
            move_host(module, base_url, headers)
            msg_tokens.append("Host was moved.")

In my environment I have to choose the folder manually so the module will move the host into the wrong folder.

Is it possible to place the host into a folder only when the host is created?

Additionally there should be an option to retrieve the folder via this module. For example with a "state: info" so I can query the folder before.

Component Name

host

Ansible Version

$ ansible --version
ansible [core 2.12.7]

[FEED] User module

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback
I know you are working on the user module and it cannot be used yet but I just wanted to let you know this and I wonder if that later works for you. :)

I tried to read all users and then only add user which is not present (just as first workaround because it is not idempotent):

---

#- name: Get existing users
#  ansible.builtin.uri:
#    url: "{{cmk_api_url}}/domain-types/user_config/collections/all"
#    headers:
#      Authorization: "Bearer {{cmk_site_user}} {{cmk_site_password}}"
#      Accept: "application/json"
#    validate_certs: "{{cmk_validate_cert}}"
#    method: GET
#  register: users
##  no_log: true

#--> Internal Server Error

#- debug:
#    var: users


- name: Create user
  ansible.builtin.uri:
    url: "{{cmk_api_url}}/domain-types/user_config/collections/all"
    headers:
      Authorization: "Bearer {{cmk_site_user}} {{cmk_site_password}}"
      Accept: "application/json"
      Content-Type: "application/json"
    validate_certs: "{{cmk_validate_cert}}"
    method: POST
    body: "{{ lookup('template','users_create.json') }}"
    body_format: json
#  when: "not users.json.value|selectattr('title', 'contains', item.name)"
  loop: "{{CMK_USERS}}"
#  no_log: true

But I got 2 problems:

  1. When getting a list of users I got following error from REST API:
{
    "detail": "'fullname'",
    "ext": {
        "crash_id": "0248bf64-d505-11ec-a331-87044f718915",
        "crash_report": {
            "href": "http://CENTRAL_HOST/cn_central/check_mk/crash.py?crash_id=0248bf64-d505-11ec-a331-87044f718915&site=cn_central",
            "method": "get",
            "rel": "cmk/crash-report",
            "type": "text/html"
        }
    },
    "status": 500,
    "title": "Internal Server Error"
}

The crash report says fullname is missing and this is the case.. but if I lookup the user in the GUI it got a Full name. (It is an LDAP user..)

  File "/omd/sites/cn_central/lib/python3/cmk/gui/wsgi/applications/rest_api.py", line 452, in _wsgi_app
    return wsgi_app(environ, start_response)
  File "/omd/sites/cn_central/lib/python3/cmk/gui/wsgi/applications/rest_api.py", line 232, in __call__
    wsgi_app = self.func(ParameterDict(path_args))
  File "/omd/sites/cn_central/lib/python3/cmk/gui/plugins/openapi/restful_objects/decorators.py", line 708, in _wrapper
    response = func(param)
  File "/omd/sites/cn_central/lib/python3/cmk/gui/plugins/openapi/restful_objects/decorators.py", line 609, in _validating_wrapper
    response = self.func(param)
  File "/omd/sites/cn_central/lib/python3/cmk/gui/plugins/openapi/endpoints/user_config.py", line 81, in list_users
    users.append(serialize_user(user_id, complement_customer(user_attributes)))
  File "/omd/sites/cn_central/lib/python3/cmk/gui/plugins/openapi/endpoints/user_config.py", line 186, in serialize_user
    title=attributes["fullname"],
{'attributes': {'auth_option': {},
                'contact_options': {'email': 'user1234@email',
                                    'fallback_contact': False},
                'contactgroups': ['cmk-operator'],
                'disable_notifications': {},
                'enforce_password_change': False,
                'idle_timeout': {'option': 'global'},
                'interface_options': {'interface_theme': 'default',
                                      'mega_menu_icons': 'topic',
                                      'navigation_bar_icons': 'show',
                                      'show_mode': 'default_show_more',
                                      'sidebar_position': 'right'},
                'roles': ['admin', 'operator']},
 'user_id': 'user1234'}
  1. When adding a user it will be added but looks not correct in the GUI (I have added a screenshot below - the last user in the screenshot was added via REST API)

Component Name

user

Ansible Version

$ ansible --version
ansible [core 2.12.5]

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk               0.2.2

Environment

Checkmk version: 2.1.0b8

Screenshots

image

Additional context

[BUG] Local variable referenced before assignment

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

I have tried to create a folder "customer" and in next task I want to create folder "project" under this "customer" folder:

- name: "Create customer folder"
  tribe29.checkmk.folder:
    server_url: "https://{{ cmk_central }}/"
    site: "{{ cmk_central_site }}"
    automation_user: "{{ cmk_site_user }}"
    automation_secret: "{{ cmk_site_password }}"
    path: "/{{ meta_project_platform | lower }}/{{ meta_customer_pretty | upper }}"
    title: "{{ meta_customer_pretty }}"
    attributes:
      "{{ CMK_FOLDER_ATTRIBUTES | default(omit) }}"
    state: "present"
  when: >
    meta_project_platform is defined
    and (meta_project_platform | lower is match("mah")
    or meta_project_platform | lower is match("gcp")
    or meta_project_platform | lower is match("aws")
    or meta_project_platform | lower is match("azure"))
  run_once: true
  delegate_to: localhost
  become: no

- name: "Create poject folder"
#  tribe29.checkmk.folder:
  checkmk_folder:
    server_url: "https://{{ cmk_central }}/"
    site: "{{ cmk_central_site }}"
    automation_user: "{{ cmk_site_user }}"
    automation_secret: "{{ cmk_site_password }}"
    path: "/{{ meta_project_platform | lower }}/{{ meta_customer_pretty | upper }}/{{ meta_project_short | upper }}"
    title: "{{ meta_project_short|upper }}"
    attributes:
      order_atom_id: "{{ meta_project_oaid }}"
    state: "present"
  when: >
    meta_project_platform is defined
    and (meta_project_platform | lower is match("mah")
    or meta_project_platform | lower is match("gcp")
    or meta_project_platform | lower is match("aws")
    or meta_project_platform | lower is match("azure"))
  run_once: true
  delegate_to: localhost
  become: no

There is also a problem for the first task but this is not important now (will open another issue for that).
But in the second task I get this error:

UnboundLocalError: local variable 'body' referenced before assignment

The reason for that are following lines (which are also in the host.py for example).
The variable body will only be defined when status == 200 - but in this case the status is 500 (i still debugging it and need to find out why it is 500). But you cannot reference body in else clause because it is only defined if status == 200.

def get_current_folder_state(module, base_url, headers):
    current_state = "unknown"
    current_explicit_attributes = {}
    etag = ""

    path_for_url = module.params["path"].replace("/", "~")

    api_endpoint = "/objects/folder_config/" + path_for_url
    url = base_url + api_endpoint

    response, info = fetch_url(module, url, data=None, headers=headers, method="GET")

    if info["status"] == 200:
        body = json.loads(response.read())
        current_state = "present"
        etag = info.get("etag", "")
        extensions = body.get("extensions", {})
        current_explicit_attributes = extensions.get("attributes", {})
        if "meta_data" in current_explicit_attributes:
            del current_explicit_attributes["meta_data"]

    elif info["status"] == 404:
        current_state = "absent"

    else:
        exit_failed(
            module,
           "Error calling API. HTTP code %d. Details: %s. Body: %s"
            % (info["status"], info["body"], body),
#            "Error calling API. HTTP code %d."
#           % (info["status"]),
        )

    return current_state, current_explicit_attributes, etag

The commented lines were just for debugging to see which http code I got.

Component Name

folder

Ansible Version

$ ansible --version
ansible [core 2.12.5]

Checkmk Version

2.1.0b8 (CEE)

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk               0.2.2

Environment

To Reproduce
Steps to reproduce the behavior:
See my example in the bug description

Expected behavior

The HTTP Error 500 should be thrown.

Actual behavior

It tries to show body but it is never defined because HTTP is not 200 for getting current folder

Screenshots

Additional context

[BUG] Task "tribe29.checkmk.agent : Create host on server." hangs up

Describe the bug

I just tried to use this role to install the checkmk agent on my server an register it at my checkmk site.

The checkmk agent is installed successfully, but it hangs up at task "Create host on server."

My vars are set similar to this:

vars:
  checkmk_agent_version: "2.1.0p12"
  checkmk_agent_edition: cre
  checkmk_agent_protocol: https
  checkmk_agent_server: checkmk.example.com
  checkmk_agent_site: monitoring
  checkmk_agent_user: automation
  checkmk_agent_secret: '<MY_SECRET>'
  checkmk_agent_add_host: 'true'
  checkmk_agent_discover: 'true'
  checkmk_agent_folder: 'My Folder'

This is the output I get when running ansible-playbook -vvv my_playbook.yaml

TASK [tribe29.checkmk.agent : Create host on server.] ********************************************************************************************************************************
task path: /home/my_user/.ansible/collections/ansible_collections/tribe29/checkmk/roles/agent/tasks/main.yml:35
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: my_user
<localhost> EXEC /bin/sh -c 'echo ~my_user && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/my_user/.ansible/tmp `"&& mkdir "` echo /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786 `" && echo ansible-tmp-1663934876.4857767-36863-111637804248786="` echo /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786 `" ) && sleep 0'
Using module file /home/my_user/.ansible/collections/ansible_collections/tribe29/checkmk/plugins/modules/host.py
<localhost> PUT /home/my_user/.ansible/tmp/ansible-local-3676448y416i9/tmpjrcqeokj TO /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786/AnsiballZ_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786/ /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786/AnsiballZ_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=<HIDDEN>] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-<HIDDEN> ; /usr/bin/python3 /home/my_user/.ansible/tmp/ansible-tmp-1663934876.4857767-36863-111637804248786/AnsiballZ_host.py'"'"' && sleep 0'

Component Name

host

Ansible Version

$ ansible --version
ansible [core 2.13.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/my_user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/my_user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]
  jinja version = 3.0.3
  libyaml = True

Checkmk Version

e.g. 2.1.0p12 (CRE)

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk   0.10.0 

Environment

Local machine: Linux Mint 21 Cinnamon
Details: https://termbin.com/uvdqt

checkmk server and client: Debian 11

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Run '....'
  3. Execute '....'
  4. See error

Expected behavior

Actual behavior

Screenshots

Additional context

[FEED] Catch error for non-running site

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

When running against a non-started site, e.g. the folder module fails with an arbitrary error message.

Component Name

folder

But affects all modules, probably.

Ansible Version

$ ansible --version
ansible [core 2.12.1]
  config file = None
  configured module search path = ['/home/robin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/robin/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/robin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/robin/.local/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 3.0.3
  libyaml = True

Checkmk Version

2.0.0p21 (CEE)

Collection Version

$ ansible-galaxy collection list
# /home/robin/.local/lib/python3.8/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0  
ansible.netcommon             2.5.0  
ansible.posix                 1.3.0  
ansible.utils                 2.4.3  
ansible.windows               1.9.0  
arista.eos                    3.1.0  
awx.awx                       19.4.0 
azure.azcollection            1.10.0 
check_point.mgmt              2.2.0  
chocolatey.chocolatey         1.1.0  
cisco.aci                     2.1.0  
cisco.asa                     2.1.0  
cisco.intersight              1.0.18 
cisco.ios                     2.6.0  
cisco.iosxr                   2.6.0  
cisco.ise                     1.2.1  
cisco.meraki                  2.5.0  
cisco.mso                     1.3.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.8.2  
cisco.ucs                     1.6.0  
cloud.common                  2.1.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 2.1.0  
community.azure               1.1.0  
community.ciscosmb            1.0.4  
community.crypto              2.0.2  
community.digitalocean        1.14.0 
community.dns                 2.0.3  
community.docker              2.0.2  
community.fortios             1.0.0  
community.general             4.2.0  
community.google              1.0.0  
community.grafana             1.3.0  
community.hashi_vault         2.1.0  
community.hrobot              1.2.1  
community.kubernetes          2.0.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.2  
community.mongodb             1.3.2  
community.mysql               2.3.2  
community.network             3.0.0  
community.okd                 2.1.0  
community.postgresql          1.6.0  
community.proxysql            1.3.0  
community.rabbitmq            1.1.0  
community.routeros            2.0.0  
community.skydive             1.0.0  
community.sops                1.2.0  
community.vmware              1.17.0 
community.windows             1.9.0  
community.zabbix              1.5.1  
containers.podman             1.9.0  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.13 
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            4.3.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.13.0 
fortinet.fortimanager         2.1.4  
fortinet.fortios              2.1.3  
frr.frr                       1.0.3  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.4  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.2.1  
inspur.sm                     1.3.0  
junipernetworks.junos         2.8.0  
kubernetes.core               2.2.2  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0 
netapp.ontap                  21.14.1
netapp.storagegrid            21.9.0 
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.4.0  
ngine_io.cloudstack           2.2.2  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.5.3  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   1.6.6  
purestorage.flasharray        1.11.0 
purestorage.flashblade        1.9.0  
sensu.sensu_go                1.12.1 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.26.0 
theforeman.foreman            2.2.0  
vyos.vyos                     2.6.0  
wti.remote                    1.0.3  

# /home/robin/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
amazon.aws        3.0.0  
community.docker  2.0.1  
community.general 4.2.0  
kubernetes.core   2.2.2  
tribe29.checkmk   0.1.0 

Environment

Ubuntu 20.04

To Reproduce
Steps to reproduce the behavior:

  1. Install the collection.
  2. Run any module against a site, which is stopped.
  3. See the error.

Expected behavior

A clear error message is printed, that the site is not running.

Actual behavior

The module prints an arbitrary error message.

Screenshots

Additional context

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'body' referenced before assignment
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/robin/.ansible/tmp/ansible-tmp-1648038837.9834654-3709847-61624087077544/AnsiballZ_folder.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.tribe29.checkmk.plugins.modules.folder', init_globals=dict(_module_fqn='ansible_collections.tribe29.checkmk.plugins.modules.folder', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 306, in <module>\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 302, in main\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 270, in run_module\n  File \"/tmp/ansible_tribe29.checkmk.folder_payload_dbeh5tjs/ansible_tribe29.checkmk.folder_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/folder.py\", line 156, in get_current_folder_state\nUnboundLocalError: local variable 'body' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

[FEED] Ability to configure services programmatically

Provide your feedback
It would be good to have an option to configure checkmk services programmatically with an ansible module (within this collection), for example tribe29.checkmk.service.

Particularly, take this use case: https://checkmk.com/blog/how-to-monitor-web-server . It should be popular among checkmk users.

Company I work at manages hundreds of web virtual hosts and DNS entries.

Having the possibility to programmatically define at least simple checks (DNS, HTTP, TCP, etc.) would be helpful and more user-friendly than doing it manually.

An alternative to using an ansible module would be implementing a terraform provider for this.

Component Name
CheckMK

Additional context
Generally, we prefer solutions that can be fully configured as a code via terraform (or similar) and automation tools such as ansible.

In our use case, we create the checkmk VPS with terraform, then use ansible to install and partially configure it.

Ideally, the checkmk VPS terraform resource can then be tainted, recreated, provisioned (in this case with ansible) and it would end up exactly the same as before the recreation (except the historical data).

Unfortunately now it can not be fully configured with ansible because of lack of necessary modules, which compromises our configuration as code approach to everything and makes it necessary to implement custom solutions, rely on backups for actual hosts and services instead of having these immutably configured as code.

[FEED] Harmonize module parameters

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback

We already digressed with the naming of module parameters, namely the name of the managed object in the below-mentioned modules. This issue serves as a ground for discussion and work tracker towards harmonization.

This issue is updated regularly.

Component Name

  • service_group
  • tag_group
  • contact_group
  • discovery -> Not applicable here. host_name makes sense, just name does not.
  • host
  • folder

Ansible Version

$ ansible --version
ansible [core 2.13.4]
  python version = 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True

Collection Version

$ ansible-galaxy collection list
Collection        Version
----------------- -------
tribe29.checkmk   0.11.0 

Environment

Screenshots

Additional context

[FEED] Integration Tests Rework

Provide your feedback

We currently have integration tests for:

  • Modules
  • The server role

For the agent role it was not possible to get something up and running in a reasonable amount of time.
All of the abovementioned integration tests show some level of flakiness. This is - as far as I can tell - related to installing Checkmk into container images not made for it. More specifically, a lot of issues point towards systemd.
In my current opinion we need full-fledged VMs to properly test all aspects of the collection. Obviously this is something we have to do on our own, but which is far from trivial.

So this issue is more of a note to everyone reading this, that the integration test are not in the best shape.
We try to keep them as useful as possible, without wasting too much time.

Component Name

  • All modules
  • All roles

Ansible Version

$ ansible --version

Collection Version

$ ansible-galaxy collection list

Environment

  • Local Docker
  • Github Actions

Screenshots

Additional context

[BUG] Race condition in activation module

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

There is a race condition in the activation module

Component Name

activation

Ansible Version

See: https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/runs/2927366173

Checkmk Version

2.0.0p26.cre

Collection Version

$ ansible-galaxy collection list
Collection        Version
----------------- -------
tribe29.checkmk   0.6.0

Environment

To Reproduce
Steps to reproduce the behavior:
Run our integration tests. In certain scenarios a task subsequent to an activation will fail.
This is not consistent, however.

Expected behavior

After the activation module finishes successfully, changes should actually be applied.

Actual behavior

See reproduction steps.

Screenshots

Additional context

[BUG] Since version 2.1.0p5 modules not working anymore

Describe the bug

Folders cannot be created because of changes in the API since 2.1.0p5

fatal: [Host1 -> localhost]: FAILED! => changed=false
  msg: 'Error calling API. HTTP code 400. Details: b''{"title": "Bad Request", "status": 400, "detail": "These fields have problems: parent", "fields": {"parent": ["The folder \''/blub/blub/bla\'' could not be found."]}}'', '

Component Name

folder, maybe also host

Ansible Version

$ ansible --version
ansible [core 2.12.5]

Checkmk Version

2.1.0p5 (CEE) and 2.1.0p6

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk               0.5.0

Environment

To Reproduce
Steps to reproduce the behavior:

- name: "Create site folder"
  tribe29.checkmk.folder:
    server_url: "https://{{ cmk_central }}/"
    site: "{{ cmk_central_site }}"
    automation_user: "{{ cmk_site_user }}"
    automation_secret: "{{ cmk_site_password }}"
    attributes:
      labels:
        test: "test123"
    path: "/BLUB/blub/BLA/FOO"
    title: "Foo"
    state: "present"
  run_once: true
  delegate_to: localhost
  become: no
  notify:
    - activate changes

Expected behavior

Actual behavior

Screenshots

Additional context

Please remove the .lower() in following line on folder.py. Please also check host.py.

ba36a79b (Lars Getwan    2022-03-11 14:29:03 +0100 125)     return str(p.parent).lower(), p.name

tribe29.checkmk.activation failed when to changes to activate [BUG]

Describe the bug
When there are no changes to activate the module returns:

{
    "changed": false,
    "http_code": -1,
    "invocation": {
        "module_args": {
            "automation_secret": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "automation_user": "<user>",
            "force_foreign_changes": true,
            "server_url": "https://<url>/",
            "site": "<sitename>",
            "sites": []
        }
    },
    "msg": "Error calling API"
}

Component Name
tribe29.checkmk.activation

Ansible Version

$ ansible --version
ansible [core 2.12.3]
  config file = /root/ansible_project_checkmk/ansible.cfg
  configured module search path = ['/root/ansible_project_checkmk/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /root/ansible_project_checkmk/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.0.3
  libyaml = True

Checkmk Version

2.1.0p9

Collection Version

$ ansible-galaxy collection list
# /root/ansible_project_checkmk/collections/ansible_collections
Collection        Version
----------------- -------
tribe29.checkmk   0.5.2  

Expected behavior
Module should return ok

Actual behavior
Module fails with "Error calling API"

[BUG] Unexpected host-update behavior

Unfortunately I was negatively surprised today. I wanted to set a new host attribute and unfortunately lost all the remaining attributes that were already set.

If I see this correctly, in the case of an update I currently have to load all existing attributes first, then enrich them with the new attributes and then process them with tribe29.checkmk.host.

I find this procedure to be extremely cumbersome and extremely inflates the ansible playbooks. I would expect the module to recognize and preserve the attributes already set unless explicitly overridden.

What did i run?

i wanted to update an existing host, with:

ansible localhost -m tribe29.checkmk.host -a 'server_url="http://localhost/" site="cmk" automation_user="automation" automation_secret="12345" host_name="myhost" state="present" attributes="{{attr}}"' -e '{"attr": {"alias": "myalias"}}'

expexted:

  • only alias attribute would change

what happend:

  • ipaddress attribute and folder was reseted to defaults

[FEED] Rules documentation improvements

I would consider this a separate issue from #153

Provide your feedback
Documentation contains:

options:
    rule:
        description: Definition of the rule as returned by the Checkmk API.
        required: true
        type: dict

The examples show:

    rule:
        conditions: {
            "host_labels": [],
            "host_name": {
                "match_on": [
                    "test1.tld"
                ],
                "operator": "one_of"
            },
            "host_tags": [],
            "service_labels": []
        }
        properties: {
            "comment": "Warning at 80%\nCritical at 90%\n",
            "description": "Allow higher memory usage",
            "disabled": false,
            "documentation_url": "https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/rules.py"
        }
        value_raw: "{'levels': (80.0, 90.0)}"

Example rule from API:

{
  "links": [
...
  ],
  "domainType": "rule",
  "id": "1222a909-cf52-4f9d-b43a-cab4f31d925d",
  "title": "sometitle",
  "members": {},
  "extensions": {
    "ruleset": "active_checks:http",
    "folder": "/",
    "folder_index": 0,
    "properties": {
      "description": "example",
      "disabled": false
    },
    "value_raw": "{'name': 'example', 'host': {'port': 80}, 'mode': ['url', {'uri': '/'}]}",
    "conditions": {
      "host_tags": [],
      "host_labels": [
        {
          "key": "role",
          "operator": "is",
          "value": "web"
        }
      ],
      "service_labels": []
    }
  }
}

So while rule is a dict as per documentation, mixing YAML and JSON in the example, while technically correct, is a bit confusing, especially when keeping it all as JSON would make grabbing what the API returns a bit easier.

Definition of the rule as returned by the Checkmk API. is also a confusing as ruleset is broken out from the rule even though it is a part of the extensions the API returns that contains the other items in the example rule: properties, conditions, value_raw.

Component Name

rules module

Collection Version

$ ansible-galaxy collection list
Collection          Version
------------------- -------
tribe29.checkmk     0.11.0

[FEED] Check mode for rules

Provide your feedback
It would be useful to have this show planned changes in ansible's --check mode.

Component Name

rule module

Ansible Version
independent

Collection Version

$ ansible-galaxy collection list
Collection          Version
------------------- -------
tribe29.checkmk     0.11.0

[FEED] Windows agent module missing

Hello,

i just came up via the check_mk forum to install the agent on my windows server. Unfortunately this collection does not provide a module to install check_mk on these OS.

If its not planed, it would be nice if there is any information on the readme that its not included.

Thanks.

[BUG] Scheduling downtimes breaks with KeyError in case of missing/incorrect information

Describe the bug
When scheduling a downtime with missing or incorrect information (e.g. non-existent host, http instead of https) the plugin downtime.py simply breaks with a KeyError - an human-readable error message is not displayed.

Component Name
The error exists in line 245 of downtime.py:

            % (host_name, info["status"], info["body"]),

The info dict might not have the key body. Replacing info["body"] with info shows all error information - which was a workaround for us.

Ansible Version

$ ansible --version
ansible [core 2.11.12]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

Checkmk Version

2.0.0p20 (CEE)

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk     0.11.0

Environment
SUSE Linux Enterprise Server 15 SP4 x86_64, Python 3.6.15

To Reproduce
Create a playbook for scheduling a downtime with incorrect information, e.g.:

    - name: schedule host downtime
      tribe29.checkmk.downtime:
        server_url: http://monitoring.hurrdurr.io
        validate_certs: false
        site: giertz
        automation_user: paulapinkepank
        automation_secret: hannahmontanalinux
        host_name: nonexistent-host.hurrdurr.io
        comment: Downtime before Maintenance
        start_after:
          minutes: 1
        end_after:
          days: 0
          hours: 2
      delegate_to: localhost

Run the playbook:

$ ansible-playbook hurrdurr.yml
...
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'body'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1667376409.075934-16706-243751570911063/AnsiballZ_downe 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1667376409.075934-16706-243751570911063/AnsiballZ_downtime.py\", line 94, in _ansiballz_main\n    invoke_module(zp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1667376409.075934-16706-243751570911063/AnsiballZ_downtime.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansibleribe29.checkmk.plugins.modules.downtime', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(cods, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in  exec(code, run_globals)\n  File \"/tmp/ansible_tribe29.checkmk.downtime_payload_w4sj__30/ansible_tribe29.checkmk.downtime_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/downtime., in <module>\n  File \"/tmp/ansible_tribe29.checkmk.downtime_payload_w4sj__30/ansible_tribe29.checkmk.downtime_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/downtime.py\", line 4 File \"/tmp/ansible_tribe29.checkmk.downtime_payload_w4sj__30/ansible_tribe29.checkmk.downtime_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/downtime.py\", line 457, in run_modulmp/ansible_tribe29.checkmk.downtime_payload_w4sj__30/ansible_tribe29.checkmk.downtime_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/downtime.py\", line 269, in set_downtime\n  Fille_tribe29.checkmk.downtime_payload_w4sj__30/ansible_tribe29.checkmk.downtime_payload.zip/ansible_collections/tribe29/checkmk/plugins/modules/downtime.py\", line 245, in _get_current_downtimes\nKeyn", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Expected behavior
A human-readable message should be displayed - e.g. Connection time-out or Non-existent host

Actual behavior
The module crashes with a missing key.

[BUG] Duplicate CRE install stanza

The stanzas at line 54 and 78 of /roles/agent/tasks/RedHat.yml are identical:

- name: "RedHat Derivates: Install Checkmk CRE Agent."
  become: true
  ansible.builtin.yum:
    name: "{{ checkmk_agent_agent.file.cre }}"
    state: present
    disable_gpg_check: true
  when: checkmk_agent_edition == "cre"
  tags:
    - install-package

Looks like a copy+paste where one is meant to be a different type, but maybe they're just straight up dupes?

https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/edf09d26062c4e13bbeb6533e211c49f693c98c3/roles/agent/tasks/RedHat.yml#L54
https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/edf09d26062c4e13bbeb6533e211c49f693c98c3/roles/agent/tasks/RedHat.yml#L78

Also, should this be Derivatives, not Derivates?

[FEED] Test Cases

This is a 'To-Do' issue to track ideas for tests

Ideas:

  • Add test for multisite environments
  • Improve discovery tests coverage
  • Add tests for role installation
  • Add test to verify successful release and publish to the Galaxy
  • Add tests for roles (Make sure to trigger them properly)
  • Add tests for 2.1 (in parallel to 2.0)
  • Improve integration tests (make more lifelike)

[FEED] Enable forced agent installation

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback

Currently, if an agent downgrade is tried, the apt module will fail with a corresponding error.
This is a sane default, but we want to empower users to override this, if necessary.

Component Name

agent role

Ansible Version

$ ansible --version
ansible [core 2.13.1]
  config file = /home/robin/Github/ansible_collections/tribe29/checkmk/ansible.cfg
  configured module search path = ['/home/robin/Github/ansible_collections/tribe29/checkmk/plugins/modules']
  ansible python module location = /home/robin/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/robin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/robin/.local/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 3.0.3
  libyaml = True

Collection Version

$ ansible-galaxy collection list
Collection        Version
----------------- -------
tribe29.checkmk   0.5.2

Environment

Screenshots

Additional context

[BUG] failed_when test in Create host on server

When adding the host to server the following error occurs:

fatal: [ph-5qhfc42 -> localhost]: FAILED! => {"changed": true, "failed_when_result": "The conditional check 'checkmk_agent_create_result.failed is true and \"The host is already part of the specified target folder\" not in checkmk_agent_create_result.msg' failed. The error was: template error while templating string: no test named 'true'. String: {% if checkmk_agent_create_result.failed is true and \"The host is already part of the specified target folder\" not in checkmk_agent_create_result.msg %} True {% else %} False {% endif %}", "msg": "Host created."}

The line of code in the role is this:

failed_when: checkmk_agent_create_result.failed is true and "The host is already part of the specified target folder" not in checkmk_agent_create_result.msg

I believe that should just be:

failed_when: checkmk_agent_create_result.failed and "The host is already part of the specified target folder" not in checkmk_agent_create_result.msg

Component Name
Agent Role - Create host on server

Ansible Version

  config file = /home/xxx/repos/ansible-collection-tribe29.checkmk/ansible.cfg
  configured module search path = ['/home/xxx/repos/ansible-collection-tribe29.checkmk/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Checkmk Version
2.1.0p8

Collection Version
devel

Environment

To Reproduce
Steps to reproduce the behavior:
Set:
checkmk_agent_add_host: 'true'

Expected behavior
Add host to server without erroring out.

Actual behavior
Errors out with the following error:
fatal: [ph-5qhfc42 -> localhost]: FAILED! => {"changed": true, "failed_when_result": "The conditional check 'checkmk_agent_create_result.failed is true and \"The host is already part of the specified target folder\" not in checkmk_agent_create_result.msg' failed. The error was: template error while templating string: no test named 'true'. String: {% if checkmk_agent_create_result.failed is true and \"The host is already part of the specified target folder\" not in checkmk_agent_create_result.msg %} True {% else %} False {% endif %}", "msg": "Host created."}

[BUG] discovery task does not change monitored services

Verify first that your issue is not already reported here.
Where possible also test if the latest release and main branch are affected too.
Complete all sections as described!

Describe the bug

"fix_all" discovery task reports changed but site does not show any changes

Component Name

discovery

Ansible Version

# ansible --version
ansible [core 2.13.5]
  config file = /home/teridon/git/ansible/ansible-test.cfg
  configured module search path = ['/home/teridon/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/teridon/.local/share/virtualenvs/ansible-LSniJhgO/lib/python3.10/site-packages/ansible
  ansible collection location = /home/teridon/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/teridon/.local/share/virtualenvs/ansible-LSniJhgO/bin/ansible
  python version = 3.10.5 (main, Jul  7 2022, 17:58:46) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  jinja version = 3.1.2
  libyaml = True

Checkmk Version

2.0.0p23 (CEE)

Collection Version

# ansible-galaxy collection list

# /home/teridon/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
ansible.posix      1.4.0
community.general  6.0.0
dellemc.openmanage 6.3.0
pfsensible.core    0.4.2
tribe29.checkmk    0.11.0

# /home/teridon/.local/share/virtualenvs/ansible-LSniJhgO/lib/python3.10/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    3.5.0
ansible.netcommon             3.1.3
ansible.posix                 1.4.0
ansible.utils                 2.6.1
ansible.windows               1.11.1
arista.eos                    5.0.1
awx.awx                       21.7.0
azure.azcollection            1.13.0
check_point.mgmt              2.3.0
chocolatey.chocolatey         1.3.1
cisco.aci                     2.2.0
cisco.asa                     3.1.0
cisco.dnac                    6.6.0
cisco.intersight              1.0.19
cisco.ios                     3.3.2
cisco.iosxr                   3.3.1
cisco.ise                     2.5.5
cisco.meraki                  2.11.0
cisco.mso                     2.0.0
cisco.nso                     1.0.3
cisco.nxos                    3.2.0
cisco.ucs                     1.8.0
cloud.common                  2.1.2
cloudscale_ch.cloud           2.2.2
community.aws                 3.6.0
community.azure               1.1.0
community.ciscosmb            1.0.5
community.crypto              2.7.0
community.digitalocean        1.22.0
community.dns                 2.3.3
community.docker              2.7.1
community.fortios             1.0.0
community.general             5.7.0
community.google              1.0.0
community.grafana             1.5.3
community.hashi_vault         3.3.1
community.hrobot              1.5.2
community.libvirt             1.2.0
community.mongodb             1.4.2
community.mysql               3.5.1
community.network             4.0.1
community.okd                 2.2.0
community.postgresql          2.2.0
community.proxysql            1.4.0
community.rabbitmq            1.2.2
community.routeros            2.3.0
community.sap                 1.0.0
community.sap_libs            1.3.0
community.skydive             1.0.0
community.sops                1.4.1
community.vmware              2.10.0
community.windows             1.11.0
community.zabbix              1.8.0
containers.podman             1.9.4
cyberark.conjur               1.2.0
cyberark.pas                  1.0.14
dellemc.enterprise_sonic      1.1.2
dellemc.openmanage            5.5.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.20.0
fortinet.fortimanager         2.1.5
fortinet.fortios              2.1.7
frr.frr                       2.0.0
gluster.gluster               1.0.2
google.cloud                  1.0.2
hetzner.hcloud                1.8.2
hpe.nimble                    1.1.4
ibm.qradar                    2.1.0
ibm.spectrum_virtualize       1.10.0
infinidat.infinibox           1.3.3
infoblox.nios_modules         1.4.0
inspur.ispim                  1.1.0
inspur.sm                     2.2.0
junipernetworks.junos         3.1.0
kubernetes.core               2.3.2
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.20.1
netapp.elementsw              21.7.0
netapp.ontap                  21.24.1
netapp.storagegrid            21.11.1
netapp.um_info                21.8.0
netapp_eseries.santricity     1.3.1
netbox.netbox                 3.8.0
ngine_io.cloudstack           2.2.4
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.2
openstack.cloud               1.10.0
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   2.2.3
purestorage.flasharray        1.14.0
purestorage.flashblade        1.10.0
purestorage.fusion            1.1.1
sensu.sensu_go                1.13.1
servicenow.servicenow         1.0.6
splunk.es                     2.1.0
t_systems_mms.icinga_director 1.31.0
theforeman.foreman            3.7.0
vmware.vmware_rest            2.2.0
vultr.cloud                   1.1.0
vyos.vyos                     3.0.1
wti.remote                    1.0.4

Environment

OS: RHEL 8.6
python 3.10.5

To Reproduce
Steps to reproduce the behavior:

# cat testing/checkmk-activate-test.yml
---
- name: "Test activation modules."
  hosts: all
  gather_facts: 'no'
  tasks:
    - name: "Create host."
      tribe29.checkmk.host:
        server_url: "{{ server_url }}"
        site: "{{ site }}"
        automation_user: "{{ automation_user }}"
        automation_secret: "{{ automation_secret }}"
        host_name: "{{ inventory_hostname }}"
        folder: /gse
        attributes:
          site: "{{ site }}"
        state: present
      delegate_to: localhost

    - name: "Discover services on host."
      tribe29.checkmk.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: "Pause to review first set of changes."
      ansible.builtin.pause:
        prompt: |
          "Feel free to review the changes in your Checkmk site: {{ site }}."
          "Press <Enter> to continue."

    - name: "Activate changes on site - Showcase no changes."
      tribe29.checkmk.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'

Expected behavior

after the discovery task, the state of the site should have at least 1 change and the GUI should show all services for the new host in the "monitored" state.

Actual behavior

The monitored host shows all services as "undecided"

Screenshots

image

Additional context

[BUG] host.py: Modifying host with same folder (e.g. just change attribute or ipaddress) fails

Seems related to these issues:
#58
#42

Playbook:

  1. First run (host never existed before) is working:
  - name: "Create a host with IP address."
    tribe29.checkmk.host:
      server_url: "https://localhost"
      site: "site"
      automation_user: "automation"
      automation_secret: "$SECRET"
      host_name: "my_host_with_ip"
      attributes:
        alias: "My Host"
        # ip_address from example is wrong:
        ipaddress: "127.0.0.1"
        tag_custom: "own_custom_tag"
      folder: "/"
      state: "present"
  1. Second run with new IP fails:
  - name: "Create a host with IP address."
    tribe29.checkmk.host:
      server_url: "https://localhost"
      site: "site"
      automation_user: "automation"
      automation_secret: "$SECRET"
      host_name: "my_host_with_ip"
      attributes:
        alias: "My Host"
        # ip_address from example is wrong:
        ipaddress: "127.0.0.2"
        tag_custom: "own_custom_tag"
      folder: "/"
      state: "present"

Result:

TASK [Create a host with IP address.] ******************************************
fatal: [site]: FAILED! => {"changed": false, "msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Invalid move action\", \"status\": 400, \"detail\": \"The host is already part of the specified target folder\"}', "}

Desired result:

TASK [Create a host with IP address.] ******************************************
changed: [site]

I found the position where "move_host()" is triggered and analyzed it:

"/" is stripped from current_folder...
https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/d94e27fe8bd598de78fe4df3c75529d7bdbc21af/plugins/modules/host.py#L284
https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/d94e27fe8bd598de78fe4df3c75529d7bdbc21af/plugins/modules/host.py#L285

        if current_folder.endswith("/"):
            current_folder = current_folder.rstrip("/")

...but not from:
https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/d94e27fe8bd598de78fe4df3c75529d7bdbc21af/plugins/modules/host.py#L287

I fixed it temporary with module.params["folder"].rstrip("/")

        if current_folder != module.params["folder"].rstrip("/"): # MU: added .rstrip("/")
            move_host(module, base_url, headers)
            msg_tokens.append("Host was moved.")

I have not checked for side-effects.

Side-note:
The example has "ip_address" as attribute, but it's actually "ipaddress".

[FEED] Implement module for distributed monitoring

Provide your feedback

Soon the REST API endpoint for distributed monitoring will be available in Checkmk.
Therefore, we want to enable this feature in the collection.
This is just a placeholder at this point, as no work has been planned yet.

Component Name

distributed

Ansible Version

$ ansible --version

Collection Version

$ ansible-galaxy collection list

Environment

Screenshots

Additional context

[BUG] cannot create sites

Describe the bug
Using the "server" role does not create a site. Rather we get an error.

Component Name
server role

Ansible Version

ansible [core 2.13.5]
  config file = /Users/mpana/Development/collaborationfactory/ansible-checkmk/ansible.cfg
  configured module search path = ['/Users/mpana/Development/collaborationfactory/ansible-checkmk/plugins/modules']
  ansible python module location = /Users/mpana/Development/collaborationfactory/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/mpana/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/mpana/Development/collaborationfactory/bin/ansible
  python version = 3.10.7 (main, Sep 15 2022, 01:51:29) [Clang 14.0.0 (clang-1400.0.29.102)]
  jinja version = 3.1.2
  libyaml = True

Checkmk Version

2.1.0p13.cre

Collection Version

Collection        Version
----------------- -------
ansible.posix     1.4.0  
community.general 5.7.0  
community.mysql   1.1.2  
tribe29.checkmk   0.11.0 

# /Users/mpana/Development/collaborationfactory/lib/python3.10/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    3.5.0  
ansible.netcommon             3.1.3  
ansible.posix                 1.4.0  
ansible.utils                 2.6.1  
ansible.windows               1.11.1 
arista.eos                    5.0.1  
awx.awx                       21.7.0 
azure.azcollection            1.13.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.3.1  
cisco.aci                     2.2.0  
cisco.asa                     3.1.0  
cisco.dnac                    6.6.0  
cisco.intersight              1.0.19 
cisco.ios                     3.3.2  
cisco.iosxr                   3.3.1  
cisco.ise                     2.5.5  
cisco.meraki                  2.11.0 
cisco.mso                     2.0.0  
cisco.nso                     1.0.3  
cisco.nxos                    3.2.0  
cisco.ucs                     1.8.0  
cloud.common                  2.1.2  
cloudscale_ch.cloud           2.2.2  
community.aws                 3.6.0  
community.azure               1.1.0  
community.ciscosmb            1.0.5  
community.crypto              2.7.0  
community.digitalocean        1.22.0 
community.dns                 2.3.3  
community.docker              2.7.1  
community.fortios             1.0.0  
community.general             5.7.0  
community.google              1.0.0  
community.grafana             1.5.3  
community.hashi_vault         3.3.1  
community.hrobot              1.5.2  
community.libvirt             1.2.0  
community.mongodb             1.4.2  
community.mysql               3.5.1  
community.network             4.0.1  
community.okd                 2.2.0  
community.postgresql          2.2.0  
community.proxysql            1.4.0  
community.rabbitmq            1.2.2  
community.routeros            2.3.0  
community.sap                 1.0.0  
community.sap_libs            1.3.0  
community.skydive             1.0.0  
community.sops                1.4.1  
community.vmware              2.10.0 
community.windows             1.11.0 
community.zabbix              1.8.0  
containers.podman             1.9.4  
cyberark.conjur               1.2.0  
cyberark.pas                  1.0.14 
dellemc.enterprise_sonic      1.1.2  
dellemc.openmanage            5.5.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.20.0 
fortinet.fortimanager         2.1.5  
fortinet.fortios              2.1.7  
frr.frr                       2.0.0  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.8.2  
hpe.nimble                    1.1.4  
ibm.qradar                    2.1.0  
ibm.spectrum_virtualize       1.10.0 
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.4.0  
inspur.ispim                  1.1.0  
inspur.sm                     2.2.0  
junipernetworks.junos         3.1.0  
kubernetes.core               2.3.2  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.20.1
netapp.elementsw              21.7.0 
netapp.ontap                  21.24.1
netapp.storagegrid            21.11.1
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.3.1  
netbox.netbox                 3.8.0  
ngine_io.cloudstack           2.2.4  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.2  
openstack.cloud               1.10.0 
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   2.2.3  
purestorage.flasharray        1.14.0 
purestorage.flashblade        1.10.0 
purestorage.fusion            1.1.1  
sensu.sensu_go                1.13.1 
servicenow.servicenow         1.0.6  
splunk.es                     2.1.0  
t_systems_mms.icinga_director 1.31.0 
theforeman.foreman            3.7.0  
vmware.vmware_rest            2.2.0  
vultr.cloud                   1.1.0  
vyos.vyos                     3.0.1  
wti.remote                    1.0.4 

Environment
MacOS Monterey 12.6
Darwin imac.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

Python 3.10.7

To Reproduce
Define a playbook to trigger site creation, for example:

---
- hosts: all
  collections:
    - tribe29.checkmk
  roles:
    - tribe29.checkmk.server
  vars_files:
    - ../vars/config.yml

  tasks:
    - name: "Run server role."
      tags: [server]
      ansible.builtin.import_role:
        name: server
        
    - name: "Create test site."
      tags: [create-sites]
      no_log: false
      ansible.builtin.import_role:
        name: server

Also create a config file with something like:

vars/config.yml 
---
checkmk_server_version: "2.1.0p13"
checkmk_server_sites: 
  - name: test
  - version: "{{ checkmk_server_version }}"
  - state: started
  - admin_pw: test

checkmk_server_download_user: [someuser]
checkmk_server_download_pass: [somepass]

checkmk_server_base_url: "https://download.checkmk.com/checkmk"
3	checkmk_server_download_url: "{{ checkmk_server_base_url }}/{{ checkmk_server_version }}/{{ checkmk_server_setup_file }}"%      

Run those with ansible-playbook:

$ ansible-playbook -i inventory/hosts.ini -l server  playbooks/deploy_server.yml -u ubuntu -b -vv

Expected behavior
The server would also get a running checkmk site as defined in the configuration file/role.

Actual behavior
TASK [tribe29.checkmk.server : Include Site Management Playbook.] ******************************************
task path: /Users/mpana/.ansible/collections/ansible_collections/tribe29/checkmk/roles/server/tasks/main.yml:85
included: /Users/mpana/.ansible/collections/ansible_collections/tribe29/checkmk/roles/server/tasks/sites.yml for teacher

TASK [tribe29.checkmk.server : Create Sites.] **************************************************************

task path: /Users/mpana/.ansible/collections/ansible_collections/tribe29/checkmk/roles/server/tasks/sites.yml:2
fatal: [teacher]: FAILED! => {"msg": "The conditional check 'item.state != "absent"' failed. The error was: error while evaluating conditional (item.state != "absent"): 'dict object' has no attribute 'state'\n\nThe error appears to be in '/Users/mpana/.ansible/collections/ansible_collections/tribe29/checkmk/roles/server/tasks/sites.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: "Create Sites."\n ^ here\n"}

Am I doing something wrong? I missed examples in the docs/elsewhere here for creating sites using plays however the role clearly defines tasks for creating sites.

Thanks!
Marius

[BUG] Ansible Galaxy import shows warning about unused variable.

Describe the bug

Ansible Galaxy import shows warning about unused variable.

Component Name

folder

Ansible Version

$ ansible --version

Collection Version

$ ansible-galaxy collection list

Environment

Ansible Galaxy.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Ansible Galaxy
  2. Import the collection
  3. Check the import log

Expected behavior

No warnings.

Actual behavior

plugins/modules/folder.py:130:5: F841 local variable 'current_folder' is assigned to but never used 
plugins/modules/folder.py:185:5: F841 local variable 'path_for_url' is assigned to but never used 

Screenshots

Additional context

[BUG] tribe29.checkmk.host is not idempotent

Describe the bug
When running the tribe29.checkmk.host for a host that already exists in check_mk (with state: present) the module returns an error.

Component Name
tribe29.checkmk.host

Ansible Version

ansible [core 2.12.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/xenorites/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/xenorites/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 12.0.1 20220308 (Red Hat 12.0.1-0)]
  jinja version = 3.0.3
  libyaml = True

Checkmk Version

2.0.0p25 (CRE)

Collection Version

0.3.3

Expected behavior
Ansible should return an "OK" status for idempotency.

Actual behavior
Ansible returns an error:

FAILED! => {"changed": false, "msg": "Error calling API. HTTP code 400. Details: b'{\"title\": \"Invalid move action\", \"status\": 400, \"detail\": \"The host is already part of the specified target folder\"}', "}

[BUG] host module fails because REST API puts trailing slash now

Please verify first that your feedback is not already reported here.
If possible and useful provide additional information below. This is optional however.

Provide your feedback
Beginning with Checkmk 2.1.0b6 the output of getting current_folder from REST API has changed. Now a trailing slash is added. So like in my case if the parameter folder had no trailing slash the condition if current_folder != module.params["folder"]: was failing after 2.1.0b5.
I added now a trailing slash and this could also be checked in the role I build but if I am correct then modules like "sychronize" and more also checking that.

Component Name

host

Ansible Version

$ ansible --version
ansible [core 2.12.5]

Collection Version

$ ansible-galaxy collection list
tribe29.checkmk               0.2.0 (also tested with 0.2.2)

Environment

Checkmk Version: 2.1.0b5 (WORKING - but maybe that would fail if folder parameter got an trailing slash)
Checkmk Version: 2.1.0b6, 2.1.0b7, 2.1.0b8 (FAILING - fixed by putting a trailing slash into folder variable)

Screenshots

Additional context

[FEED] Add tags to the roles to allow for more flexible runs

I propose we add tags to all tasks in the roles from this collection.
I've used this collection to deploy 9 Checkmk sites (and counting!) over the past 2 weeks! It works great, however in networks where network access is restricted, or blocked completely, these roles cease to function at all. I have had to resort to just commenting out sections of code and doing the failed tasks manually.

It would be great to skip tasks like downloading packages. The role does so much, which while configurable, still isn't very flexible. The roles still have a lot of function that might not be desired in a specific run. Of course it would be possible to add more booleans, but I feel adding tags is the preferred way of doing this. The booleans we have now still make sense, since those are ones that you likely want to configure per-host.

I've even used this role to bulk import existing hosts into a Checkmk site. Since we had an inventory of them already, I just ran the agent role with all the tasks except the host and discovery tasks commented out.

Sometimes if the agent hosts can not reach the Checkmk server on the HTTP port this will result in it completely failing. If we were to add tags to all tasks that download files, these files could still be sent to the servers in other means (Like pre_tasks in the playbook).

Of course, editing the code before running it isn't a very good solution to this. Giving every task a tag would allow specific tasks to be skipped with --skip-tags or only certain tasks to be ran with --tags (or given in the playbook).

If this is a wanted I can create a PR for this.

If so, would we want tasks to have a prefix or not? eg. checkmk_server_download or just download? If you have a complicated playbook with multiple roles, you should be passing this along per role anyway, so I think just download would be fine and looks cleaner and less cluttered.

[BUG] role not (yet) stable on 22.04

Hi all,

I'm trying to setup a cme server on a 22.04 host and sadly got this message:

TASK [tribe29.checkmk.server : Preflight - Fail if target host is not stable for this Role.] *****************************
fatal: [ans-tst]: FAILED! => {"changed": false, "msg": "This role is not stable for the target operating system, Ubuntu 22."}

Is there anything I could do to give it a try anyways?

And if it fails what could I do to support in getting it to work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.