Create rules in Ansible targeting RestAPI

This drives me nuts so I just wanted to check if anyone here have found a solution / are using something similar.

I want to create a number of rules using the rest API. As the rules Rest API does not work with JSON and instead require a Python dict for “raw_data” its really hard to use any other language

As Ansible will escape any ansible variable used in jinja2 , for example

raw_data: “{ ‘label:’ ‘{{ ansible_variable }}’ }”

Checkmk will complain saying my value is not a string (as its escaped like "
Is there a way of solving this without having to write a python module?

I had the same problems in a project where we where using PHP and I had to remove the ESCAPE after the JOSN was produced, any change this can be done as well?

Hey @Anders! :wave:
I am afraid I have no good answer, but I can point you to these resources:

I have tried many options and even asked ChatGTP for some guidelines, I have even tested to create the dict using some loops and almost manually created the JSON.

But it’s *** impossible to tell Ansible to not to touch a specific value as it should be treated like a dict.

Currently I’m thinking just to call an external script from Ansible when creating my rules as this blocks everything.

This was possible and now I can use Ansible to create over 40 Service labels.

1 Like

I do agree, that the situation is frustrating, although a lot of rules work well with our module.

Maybe you want to share your solution? We feature community content that augments or builds on the collection. :slight_smile:

1 Like