diff --git a/changelogs/fragments/agent.yml b/changelogs/fragments/agent.yml index f18339599..84cbbeb11 100644 --- a/changelogs/fragments/agent.yml +++ b/changelogs/fragments/agent.yml @@ -1,2 +1,4 @@ minor_changes: - Agent role - Allow the role to download folder-specific agents. +bugfixes: + - Agent role - Fix agent and update registration on remote sites. diff --git a/roles/agent/tasks/Debian.yml b/roles/agent/tasks/Debian.yml index 67b61f986..6f67bfca4 100644 --- a/roles/agent/tasks/Debian.yml +++ b/roles/agent/tasks/Debian.yml @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 diff --git a/roles/agent/tasks/Linux.yml b/roles/agent/tasks/Linux.yml index 6e4eb5d8c..d6a4c81e1 100644 --- a/roles/agent/tasks/Linux.yml +++ b/roles/agent/tasks/Linux.yml @@ -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 @@ -67,13 +68,11 @@ become: true ansible.builtin.shell: | cmk-update-agent register -H {{ checkmk_agent_host_name }} \ - -s {{ checkmk_agent_server }} -i {{ checkmk_agent_site }} -p {{ checkmk_agent_protocol }} \ + -s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} -p {{ checkmk_agent_protocol }} \ -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) @@ -83,13 +82,11 @@ become: true ansible.builtin.shell: | cmk-update-agent register -H {{ checkmk_agent_host_name }} \ - -s {{ checkmk_agent_server }} -i {{ checkmk_agent_site }} -p {{ checkmk_agent_protocol }} \ + -s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} -p {{ checkmk_agent_protocol }} \ -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) @@ -98,7 +95,7 @@ become: true ansible.builtin.shell: | cmk-agent-ctl register -H {{ checkmk_agent_host_name }} \ - -s {{ checkmk_agent_server }} -i {{ checkmk_agent_site }} \ + -s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} \ -U {{ checkmk_agent_user }} -P {{ checkmk_agent_auth }} --trust-cert register: checkmk_agent_tls_state when: | diff --git a/roles/agent/tasks/RedHat.yml b/roles/agent/tasks/RedHat.yml index 9230f2fe5..3b0a33adb 100644 --- a/roles/agent/tasks/RedHat.yml +++ b/roles/agent/tasks/RedHat.yml @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 diff --git a/roles/agent/tasks/Suse.yml b/roles/agent/tasks/Suse.yml index afa7d606f..fe68cdd45 100644 --- a/roles/agent/tasks/Suse.yml +++ b/roles/agent/tasks/Suse.yml @@ -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 }}" @@ -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 @@ -27,22 +24,19 @@ 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 community.general.zypper: name: "{{ checkmk_agent_agent.file.host }}" @@ -50,15 +44,12 @@ 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 }}" @@ -70,10 +61,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 @@ -88,7 +76,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 }}" @@ -99,32 +87,26 @@ 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 community.general.zypper: name: "{{ checkmk_agent_agent.file.cee }}" @@ -132,21 +114,29 @@ 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 community.general.zypper: name: "{{ checkmk_agent_agent.file.cre }}" force: "{{ checkmk_agent_force_install | bool }}" state: present disable_gpg_check: true - when: checkmk_agent_edition == "cre" + when: checkmk_agent_edition | lower == "cre" tags: - install-package diff --git a/roles/agent/tasks/Win32NT.yml b/roles/agent/tasks/Win32NT.yml index 4560a0d2c..876b21f78 100644 --- a/roles/agent/tasks/Win32NT.yml +++ b/roles/agent/tasks/Win32NT.yml @@ -43,10 +43,7 @@ args: chdir: "C:\\Program Files (x86)\\checkmk\\service\\" 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_binary.stat.exists | bool and checkmk_agent_update | bool and (checkmk_agent_pass is defined and checkmk_agent_pass | length) @@ -61,10 +58,7 @@ args: chdir: "C:\\Program Files (x86)\\checkmk\\service\\" 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_binary.stat.exists | bool and checkmk_agent_update | bool and (checkmk_agent_secret is defined and checkmk_agent_secret | length) diff --git a/roles/agent/tasks/Windows.yml b/roles/agent/tasks/Windows.yml index 04954ff50..5c8750649 100644 --- a/roles/agent/tasks/Windows.yml +++ b/roles/agent/tasks/Windows.yml @@ -1,18 +1,18 @@ --- -- name: "{{ ansible_os_family }}: Download Checkmk CRE Agent." +- name: "{{ ansible_os_family }}: Download Vanilla {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_get_url: url: "{{ checkmk_agent_agent.url.cre }}" validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}" dest: "{{ checkmk_agent_agent.file.cre }}" - 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" tags: - download-package -- name: "{{ ansible_os_family }}: Download host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent." +- name: "{{ ansible_os_family }}: Download host-specific {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_get_url: url: "{{ checkmk_agent_agent.url.cee }}?host_name={{ checkmk_agent_host_name }}&os_type=windows_msi&agent_type=host_name" validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}" @@ -22,10 +22,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" register: checkmk_agent_host_download_state # This task may fail, as we fall back to the generic agent in that case failed_when: 'false' @@ -39,20 +36,17 @@ checkmk_agent_host_specific: >- {{ (checkmk_agent_host_download_state.status_code is defined and checkmk_agent_host_download_state.status_code == 200) | bool }} -- name: "{{ ansible_os_family }}: Install host-specific Checkmk {{ checkmk_agent_edition | upper }} Agent." +- name: "{{ ansible_os_family }}: Install host-specific {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_package: path: "{{ checkmk_agent_agent.file.host }}" 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.windows.win_get_url: url: "{{ checkmk_agent_agent.url.cee }}?os_type=windows_msi&agent_type=generic&folder_name={{ checkmk_agent_folder }}" validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}" @@ -63,10 +57,7 @@ Accept: "application/octet-stream" 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 @@ -81,7 +72,7 @@ checkmk_agent_folder_specific: >- {{ (checkmk_agent_folder_download_state.status_code is defined and checkmk_agent_folder_download_state.status_code == 200) | bool }} -- name: "{{ ansible_os_family }}: Download GENERIC Checkmk {{ checkmk_agent_edition | upper }} Agent." +- name: "{{ ansible_os_family }}: Download GENERIC {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_get_url: url: "{{ checkmk_agent_agent.url.cee }}?os_type=windows_msi&agent_type=generic" validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}" @@ -91,33 +82,27 @@ 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" 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 }}: Install GENERIC or folder-specific Checkmk {{ checkmk_agent_edition | upper }} Agent." +- name: "{{ ansible_os_family }}: Install GENERIC or folder-specific {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_package: path: "{{ checkmk_agent_agent.file.cee }}" 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 }}: Install Checkmk CRE Agent." +- name: "{{ ansible_os_family }}: Install Vanilla {{ checkmk_agent_edition | upper }} Agent." ansible.windows.win_package: path: "{{ checkmk_agent_agent.file.cre }}" state: present - when: checkmk_agent_edition == "cre" + when: checkmk_agent_edition | lower == "cre" tags: - install-package diff --git a/roles/agent/tasks/main.yml b/roles/agent/tasks/main.yml index 57ae2ce1a..bd414bc8f 100644 --- a/roles/agent/tasks/main.yml +++ b/roles/agent/tasks/main.yml @@ -1,4 +1,9 @@ --- +- name: "Preflight - Fail if Checkmk Edition is incorrect." + ansible.builtin.fail: + msg: "The provided Checkmk Edition '{{ checkmk_agent_edition }}' does not exist or is not supported by this role." + when: checkmk_agent_edition | lower not in checkmk_agent_edition_mapping + - name: "Include OS family specific variables." ansible.builtin.include_vars: "{{ ansible_os_family }}.yml" tags: diff --git a/roles/agent/vars/main.yml b/roles/agent/vars/main.yml index f6a712bf6..6211fb2a7 100644 --- a/roles/agent/vars/main.yml +++ b/roles/agent/vars/main.yml @@ -2,3 +2,11 @@ checkmk_agent_site_url: "{{ checkmk_agent_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_port }}/{{ checkmk_agent_site }}" checkmk_agent_auth: "{% if checkmk_agent_secret is defined and checkmk_agent_secret | length %}{{ checkmk_agent_secret }}{% else %}{{ checkmk_agent_pass }}{% endif %}" # noqa yaml[line-length] + +# Due to inconsistent naming of editions, we normalize them here for convenience +checkmk_agent_edition_mapping: + cre: raw + cfe: free + cee: enterprise + cce: cloud + cme: managed