Checkmk / ansible-collection-checkmk.general

The official Checkmk Ansible collection - brought to you by the Checkmk company.
https://galaxy.ansible.com/checkmk/general
GNU General Public License v3.0
114 stars 53 forks source link

[BUG] Agent role crashes, when connections file absent #634

Open robin-checkmk opened 2 weeks ago

robin-checkmk commented 2 weeks ago

Also the role crashes when a file doesn't exist:

fatal: [<redacted>]: FAILED! => changed=false
  cmd:
  - cat
  - /var/lib/cmk-agent/registered_connections.json
  delta: '0:00:00.006522'
  end: '2024-07-02 16:23:50.121297'
  msg: non-zero return code
  rc: 1
  start: '2024-07-02 16:23:50.114775'
  stderr: 'cat: /var/lib/cmk-agent/registered_connections.json: No such file or directory'
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

I noticed this issue on Rapberry Pis, so maybe the path is different on arm?

Originally posted by @mueller-ma in https://github.com/Checkmk/ansible-collection-checkmk.general/issues/631#issuecomment-2203366127

robin-checkmk commented 2 weeks ago

Curious. The failed_when directive should make the task not fail, if the rc is 0 or 1, as the latter means an absent file, which is fine. Let me double-check this.

- name: "{{ ansible_system }}: Read Updater State."
  become: true
  ansible.builtin.command: cat /var/lib/check_mk_agent/cache/plugins_cmk-update-agent.cache
  register: __checkmk_agent_updater_state
  changed_when: false
  failed_when: |
    not __checkmk_agent_updater_state.rc == 0
    and not __checkmk_agent_updater_state.rc == 1
robin-checkmk commented 1 week ago

@mueller-ma I cannot reproduce this issue. For me the failed_when logic works just fine. No matter if the file exists or not, the task is fine. Can you double-check on your end? Do you have any non-default Ansible configuration on place?

mueller-ma commented 1 week ago

There're two tasks using cat, but only one of them catches failure code == 1: https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/roles/agent/tasks/Linux.yml#L90-L103

robin-checkmk commented 1 week ago

You successfully confused me with the two different problems in this one issue! :grin:

I just pushed a fix, which will be released with the next release.