-
Notifications
You must be signed in to change notification settings - Fork 60
[BUG] Conflict updating a host's attributes while moving it to another folder #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It is not a bug! It is explicitly designed that way, (see also the error message!) The problem is as follows: |
I'm aware, that on the module level, that's the expected behavior. Including the |
I think @eliasp has a point. I have seen the issue a while back, but IIRC I had an error in my configuration. |
The following should do the job - name: "{{ ansible_system }}: Create (or move existing) host on server."
checkmk.general.host:
server_url: "{{ checkmk_agent_server_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_server_port }}/"
site: "{{ checkmk_agent_site }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
automation_user: "{{ checkmk_agent_user }}"
automation_secret: "{{ __checkmk_agent_auth }}"
folder: "{{ checkmk_agent_folder | default(omit) }}"
name: "{{ checkmk_agent_host_name }}"
state: "present"
become: false
register: __checkmk_agent_create_result
failed_when: |
(__checkmk_agent_create_result.failed == true) and
("The host is already part of the specified target folder" not in __checkmk_agent_create_result.msg)
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
when: checkmk_agent_add_host | bool
notify: "Activate changes"
- name: "{{ ansible_system }}: Update host attributes on server."
checkmk.general.host:
server_url: "{{ checkmk_agent_server_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_server_port }}/"
site: "{{ checkmk_agent_site }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
automation_user: "{{ checkmk_agent_user }}"
automation_secret: "{{ __checkmk_agent_auth }}"
folder: "{{ checkmk_agent_folder | default(omit) }}"
name: "{{ checkmk_agent_host_name }}"
attributes: "{{ checkmk_agent_host_attributes }}"
state: "present"
become: false
register: __checkmk_agent_create_result
failed_when: |
(__checkmk_agent_create_result.failed == true) and
("The host is already part of the specified target folder" not in __checkmk_agent_create_result.msg)
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
when: checkmk_agent_add_host | bool
notify: "Activate changes"
|
So I took a look at this and I am not sure, if I agree. While a "fix" as proposed by @msekania (thanks, buddy!) would solve your issue, I think there is something more to it. The role's functionality to add a host targets exactly that: Adding a host. If the host you are adding is already part of your monitoring, you should set Having the role move an existing host sounds way more surprising to me, than failing like in the initial description. What do you gentlemen think? |
I'm looking at this from a declarative/continuous desired state configuration perspective, not from an imperative "execute a one-shot task" point-of-view. An object's state might change (as in our case due to unrelated external factors) and it should be possible to reconcile it at any given time, by applying the declarative definition to the control mechanism and have it figure out the necessary actions to fill this delta. Compare this with using Ansible to maintain a certain set of packages that should be installed at any given time:
In this case, I wouldn't expect to require the author of the used Ansible task to implement a special case to handle the situation of package B being absent. Now in this specific case, I don't want to build additional complexity around using this role - executing it once with Having the host present, in a given folder is just the declarative input I provide to the role, which then again should figure out the required steps to reconcile the delta between "declaration" and "current state". |
You got me there mister! There is a loophole in the Ansible zen though:
The reason I build the role the way it is now, is due to these two points: Users of this collection are likely no Ansible gurus. And while your point would make it proper idempotent, I am worried that a lot of users would be surpised by existing hosts being moved. I think we even had an issue about that back when. So eventually I think this comes down to a compromise between usability and dogma. I am not saying my assumption is correct. Nor am I saying yours is wrong. I am genuinely concerned about the best way forward. I have some thoughts, maybe y'all are up to discuss them to find out which provides most merrit:
|
Hi @robin-checkmk, I see the points and would rather opt for 1 and 3 (3 would help anyway) to avoid further surprises. |
Hi, I faced the same issue with module Context: we are generating the yaml manifest with the hosts to be imported/updated in Checkmk using another tool. In this tool there's a validation mechanism of the changes, which will highlight any change of folder and attributes. |
Describe the bug
Updating attributes of a host and updating its folder at the same time fails.
Component Name
Component Name: agent
Ansible Version
Checkmk Version and Edition
e.g. 2.2.0p26 (CRE)
Collection Version
To Reproduce
Steps to reproduce the behavior:
ansible.builtin.include_role
to execute thecheckmk.general.agent
rolecheckmk_agent_folder
andcheckmk_agent_host_ip
checkmk_agent_folder
Create host on server.
with the following error:Expected behavior
I'd expect
checkmk.general.agent
to handle this conflict transparently:Actual behavior
Due to a bug in Checkmk, where the deletion of a host doesn't invalidate its DNS cache, I have to set the host's IP explicitly via
checkmk_agent_host_ip
.This adds the IP to
checkmk_agent_host_attributes
, which in turn is passed asattributes
to the modulecheckmk.general.host
.The Checkmk REST API apparently doesn't allow to modify a host's attributes at the same time as updating a host's folder and returns the corresponding error.
Minimum reproduction example
playbook_checkmk.yml
:ansible-playbook playbook_checkmk.yml -i [REDACTED], --extra-vars checkmk_agent_secret=[REDACTED]
Additional context
For now, I work around this problem with just this tasks before including the role:
The text was updated successfully, but these errors were encountered: