Open clagio opened 1 year ago
@pandvan the second issue you are mentioning is out of the scope of this issue. But you can control, where rules are created and if you want to be 100% certain of their position, you can look up the existing rules with the new lookup plugins, which we just released. Anyway, regarding this specific aspect, please open a dedicated issue, if you feel like this is something we should discuss.
Regarding the main discussion, I have no update yet.
in issue #523 I described the issue we are facing, which is in fact the same issue as described here. Characters get replaced in value_raw when using ansible.
While using the exact same value_raw via Swagger UI, it works as expected. I did read this entire issue, however not really sure what the exact issue is now, or what a workaround for the issue is.
in regards of the main discussion, i am not into API/ansible enough to provide any valuable input there.
So i have fixed the conversion issue by just passing the value_raw as a string to the ansible module:
checkmk.general.rule:
automation_secret: "{{ automation_secret }}"
automation_user: "{{ automation_user }}"
rule:
conditions: "{{ item.rule.conditions }}"
properties:
description: "{{ item.rule.properties.description }}"
comment: "{{ item.rule.properties.comment | default() }}"
disabled: "{{ item.rule.properties.disabled | default(False) }}"
documentation_url: "{{ documentation_url }}"
value_raw: "{{ item.rule.value_raw|string }}"
location: "{{ item.rule.location }}"
ruleset: "{{ item.ruleset }}"
server_url: "{{ master_site_baseurl }}"
site: "{{ master_site }}"
loop: "{{ rulesets | flatten(levels=1) }}"
loop_control:
label: "{{ item.ruleset }} [{{ item.rule.properties.description | default() }}]"
reading through all the comments above i see this has been provided as a workaround more often, it just disappeared in the amount of comments in this bug.
I have given up on this. The API is not consistent and the module logic is not consistent.
3 examples:
Service discovery rules->Disabled services 3 rules work ("changed" when new or changed, "ok" when nothing to do):
Check DNS service: Always says "changed". Always creates a new rule.
Memory levels for Windows/Linux/ESX: Always says "changed", even if the content is the same and the rule is not actively updated. Rules are created only once. Cosmetic problem: "changed" is wrong from logic view, rest works as expected.
I work around this with deleting rules.mk and writing the rulesets with ansible again.
Without a full compare (ansible module task) and a reliable source of the real rule content (API task) there will be no solution to this problem.
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
Checkmk Version
Collection Version
To Reproduce Steps to reproduce the behavior: Execute this task:
If I replace
value_raw: "{{ myvariable }}"
tovalue_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:
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.