Skip to content
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

Simplify and bugfix agent role #412

Merged
64 changes: 27 additions & 37 deletions roles/agent/tasks/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "{{ ansible_os_family }} Derivatives: Download host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download host-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?host_name={{ checkmk_agent_host_name }}&os_type=linux_deb&agent_type=host_name"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -9,10 +9,7 @@
Authorization: "Bearer {{ checkmk_agent_user }} {{ checkmk_agent_auth }}"
Accept: "application/octet-stream"
when: |
checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme"
checkmk_agent_edition | lower != "cre"
become: false
register: checkmk_agent_host_download_state
# This task may fail, as we fall back to the generic agent in that case
Expand All @@ -27,37 +24,31 @@
checkmk_agent_host_specific: >-
{{ (checkmk_agent_host_download_state.status is defined and checkmk_agent_host_download_state.status == 200) | bool }}

- name: "{{ ansible_os_family }} Derivatives: Transfer host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer host-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.host }}"
dest: "{{ checkmk_agent_agent.file.host }}"
mode: "0644"
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_host_specific | bool
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.apt:
deb: "{{ checkmk_agent_agent.file.host }}"
force: "{{ checkmk_agent_force_install | bool }}"
state: present
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_host_specific | bool
tags:
- install-package

- name: "{{ ansible_os_family }} Derivatives: Download folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download folder-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?os_type=linux_deb&agent_type=generic&folder_name={{ checkmk_agent_folder }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -69,10 +60,7 @@
become: false
register: checkmk_agent_folder_download_state
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_folder is defined
and not checkmk_agent_host_specific | bool
retries: 3
Expand All @@ -87,7 +75,7 @@
checkmk_agent_folder_specific: >-
{{ (checkmk_agent_folder_download_state.status is defined and checkmk_agent_folder_download_state.status == 200) | bool }}

- name: "{{ ansible_os_family }} Derivatives: Download GENERIC Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download GENERIC {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?os_type=linux_deb&agent_type=generic"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -98,52 +86,54 @@
Accept: "application/octet-stream"
become: false
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not (checkmk_agent_host_specific | bool or checkmk_agent_folder_specific | bool)
retries: 3
delegate_to: "{{ checkmk_agent_delegate_download }}"
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Transfer GENERIC or folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer GENERIC or folder-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.cee }}"
dest: "{{ checkmk_agent_agent.file.cee }}"
mode: "0644"
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not checkmk_agent_host_specific | bool
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install GENERIC or folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Install GENERIC or folder-specific {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.apt:
deb: "{{ checkmk_agent_agent.file.cee }}"
force: "{{ checkmk_agent_force_install | bool }}"
state: present
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not checkmk_agent_host_specific | bool
tags:
- install-package

- name: "{{ ansible_os_family }} Derivatives: Install Checkmk CRE Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer Vanilla {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.cre }}"
dest: "{{ checkmk_agent_agent.file.cre }}"
mode: "0644"
when: |
checkmk_agent_edition | lower == "cre"
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install Vanilla {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.apt:
deb: "{{ checkmk_agent_agent.file.cre }}"
force: "{{ checkmk_agent_force_install | bool }}"
state: present
when: checkmk_agent_edition == "cre"
when: checkmk_agent_edition | lower == "cre"
tags:
- install-package
15 changes: 6 additions & 9 deletions roles/agent/tasks/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
checkmk_agent_prep_legacy | bool
and ansible_facts.packages['systemd'][0]['version'] | regex_search('\d{1,}') | int < 220

- name: "{{ ansible_system }}: Download Checkmk CRE agent."
- name: "{{ ansible_system }}: Download Vanilla {{ checkmk_agent_edition | upper }} agent."
ansible.builtin.get_url:
url: "{{ checkmk_agent_agent.url.cre }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
dest: "{{ checkmk_agent_agent.file.cre }}"
mode: '0640'
when: checkmk_agent_edition == "cre"
when: checkmk_agent_edition | lower == "cre"
register: result
retries: 3
delay: 10
until: "result.changed | bool"
until: "not result.failed | bool"
delegate_to: "{{ checkmk_agent_delegate_download }}"
tags:
- download-package

Expand Down Expand Up @@ -71,9 +72,7 @@
-U {{ checkmk_agent_user }} -P {{ checkmk_agent_auth }}
register: checkmk_agent_update_state
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_updater_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_pass is defined and checkmk_agent_pass | length)
Expand All @@ -87,9 +86,7 @@
-U {{ checkmk_agent_user }} -S {{ checkmk_agent_auth }}
register: checkmk_agent_update_state
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_updater_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_secret is defined and checkmk_agent_secret | length)
Expand Down
64 changes: 27 additions & 37 deletions roles/agent/tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "{{ ansible_os_family }} Derivatives: Download host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download host-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?host_name={{ checkmk_agent_host_name }}&os_type=linux_rpm&agent_type=host_name"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -9,10 +9,7 @@
Authorization: "Bearer {{ checkmk_agent_user }} {{ checkmk_agent_auth }}"
Accept: "application/octet-stream"
when: |
checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme"
checkmk_agent_edition | lower != "cre"
become: false
register: checkmk_agent_host_download_state
# This task may fail, as we fall back to the generic agent in that case
Expand All @@ -27,37 +24,31 @@
checkmk_agent_host_specific: >-
{{ (checkmk_agent_host_download_state.status is defined and checkmk_agent_host_download_state.status == 200) | bool }}

- name: "{{ ansible_os_family }} Derivatives: Transfer host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer host-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.host }}"
dest: "{{ checkmk_agent_agent.file.host }}"
mode: "0644"
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_host_specific | bool
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Install host-specific {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.yum:
name: "{{ checkmk_agent_agent.file.host }}"
state: present
disable_gpg_check: true
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_host_specific | bool
tags:
- install-package

- name: "{{ ansible_os_family }} Derivatives: Download folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download folder-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?os_type=linux_rpm&agent_type=generic&folder_name={{ checkmk_agent_folder }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -69,10 +60,7 @@
become: false
register: checkmk_agent_folder_download_state
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and checkmk_agent_folder is defined
and not checkmk_agent_host_specific | bool
retries: 3
Expand All @@ -87,7 +75,7 @@
checkmk_agent_folder_specific: >-
{{ (checkmk_agent_folder_download_state.status is defined and checkmk_agent_folder_download_state.status == 200) | bool }}

- name: "{{ ansible_os_family }} Derivatives: Download GENERIC Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Download GENERIC {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.uri:
url: "{{ checkmk_agent_agent.url.cee }}?os_type=linux_rpm&agent_type=generic"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
Expand All @@ -98,53 +86,55 @@
Accept: "application/octet-stream"
become: false
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not (checkmk_agent_host_specific | bool or checkmk_agent_folder_specific | bool)
retries: 3
delegate_to: "{{ checkmk_agent_delegate_download }}"
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Transfer GENERIC or folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer GENERIC or folder-specific {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.cee }}"
dest: "{{ checkmk_agent_agent.file.cee }}"
mode: "0644"
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not checkmk_agent_host_specific | bool
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install GENERIC or folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent."
- name: "{{ ansible_os_family }} Derivatives: Install GENERIC or folder-specific {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.yum:
name: "{{ checkmk_agent_agent.file.cee }}"
state: present
disable_gpg_check: true
when: |
(checkmk_agent_edition == "cee" or
checkmk_agent_edition == "cce" or
checkmk_agent_edition == "cfe" or
checkmk_agent_edition == "cme")
checkmk_agent_edition | lower != "cre"
and not checkmk_agent_host_specific | bool
tags:
- install-package

- name: "{{ ansible_os_family }} Derivatives: Install Checkmk CRE Agent."
- name: "{{ ansible_os_family }} Derivatives: Transfer Vanilla {{ checkmk_agent_edition | upper }} Agent."
ansible.builtin.copy:
src: "{{ checkmk_agent_agent.file.cre }}"
dest: "{{ checkmk_agent_agent.file.cre }}"
mode: "0644"
when: |
checkmk_agent_edition | lower == "cre"
and checkmk_agent_delegate_download != inventory_hostname
tags:
- download-package

- name: "{{ ansible_os_family }} Derivatives: Install Vanilla {{ checkmk_agent_edition | upper }} Agent."
become: true
ansible.builtin.yum:
name: "{{ checkmk_agent_agent.file.cre }}"
state: present
disable_gpg_check: true
when: checkmk_agent_edition == "cre"
when: checkmk_agent_edition | lower == "cre"
tags:
- install-package

Expand Down
Loading