diff --git a/defaults/main.yml b/defaults/main.yml index 7336753..4370875 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,10 +9,27 @@ cmk_omd_site: your-checkmk-site # e.g the first piece after the / following your # adds new hosts by default to Unsorted folder # cmk_folder: your_folder_in_WATO -# Copy paste the link address for rpm agent from CheckMK -cmk_rpm_agent: http://url-from-your-agent-bakery-in-checkmk.rpm -# Copy paste the link address for MSI (Windows) agent from CheckMK -cmk_msi_agent: http://url-from-your-agent-bakery-in-checkmk.msi +cmk_download_mode: samba +cmk_smb_password: ~ +cmk_smb_username: ~ + +# If using direct download (http) from CMK set below +# # Copy paste the link address for rpm agent from CheckMK +# cmk_rpm_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.rpm +# # Copy paste the link address for MSI (Windows) agent from CheckMK +# cmk_msi_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.msi +# # Copy paste from cmk server +# cmk_deb_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.deb +# # Copy paste from cmk server +# cmk_rpm_agent_aarch64: http://url-from-your-agent-bakery-in-checkmk.rpm +# # Copy paste from cmk server +# cmk_deb_agent_aarch64: http://url-from-your-agent-bakery-in-checkmk.deb + +# Want to use Samba to download the pre-prepared agents +cmk_download_path: \\fileserver\Software\checkmk-agents\{{ cmk_os_family }}\{{ansible_architecture}}\ +cmk_rpm_agent: check-mk-agent-2.0.0p11.noarch.rpm +cmk_deb_agent: check-mk-agent-2.0.0p11_all.deb +cmk_msi_agent: check-mk-agent-2.0.0p11.msi # Check_MK GPG Key # Copy paste the link address from Signature Keys for Signing Agents page diff --git a/tasks/RedHat-register.yml b/tasks/RedHat-register.yml index 02db0e5..3e8a37a 100644 --- a/tasks/RedHat-register.yml +++ b/tasks/RedHat-register.yml @@ -1,11 +1,19 @@ - block: - name: Register with CheckMK Update Server shell: | - cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \ + cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} \ + --user {{ cmk_username }} \ --secret {{ cmk_secret }} changed_when: false notify: remove agent tags: cmk_register + + - name: Check-In with server + shell: | + cmk-update-agent -v + changed_when: false + notify: remove agent + tags: cmk_register rescue: - name: Gather facts of packages package_facts: @@ -13,9 +21,10 @@ tags: cmk_register - name: Ensure check_mk_agent installed (again) - command: /usr/bin/yum install --nogpgcheck -y /tmp/check-mk-agent.rpm - args: - warn: no + package: + name: /tmp/check-mk-agent.rpm + state: latest + skip_gpg_check: true notify: - restart xinetd - ensure firewall open @@ -29,9 +38,16 @@ - name: Register with CheckMK Update Server (retry) shell: | - cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \ + cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} --user {{ cmk_username }} \ --secret {{ cmk_secret }} changed_when: false when: "'check-mk-agent' in ansible_facts.packages" notify: remove agent tags: cmk_register + + - name: Check-In with server + shell: | + cmk-update-agent -v + changed_when: false + notify: remove agent + tags: cmk_register \ No newline at end of file diff --git a/tasks/host-configure.yml b/tasks/host-configure.yml index 72cabff..e52797a 100644 --- a/tasks/host-configure.yml +++ b/tasks/host-configure.yml @@ -1,4 +1,5 @@ --- + - name: cmk_discovery uri: method: POST @@ -27,3 +28,36 @@ when: "cmk_add_host and output.result_code == 0" delegate_to: localhost tags: cmk_register + +- name: Wait some time + pause: + seconds: 10 + +- name: cmk_discovery x 2 + uri: + method: POST + url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}" + body: 'request={"hostname":"{{ instance_name | default(inventory_hostname) }}"}' + body_format: raw + status_code: 200 + validate_certs: no + follow_redirects: yes + become: no + when: "cmk_add_host and output.result_code == 0" + delegate_to: localhost + tags: cmk_register + +- name: cmk_apply + uri: + method: POST + url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=activate_changes&mode=specific{{ cmk_auth }}" + body: 'request={"sites":["{{ cmk_omd_site }}"]}' + body_format: raw + status_code: 200 + validate_certs: no + follow_redirects: yes + become: no + run_once: true + when: "cmk_add_host and output.result_code == 0" + delegate_to: localhost + tags: cmk_register diff --git a/tasks/host-management.yml b/tasks/host-management.yml index 2f0b5b1..dc47d41 100644 --- a/tasks/host-management.yml +++ b/tasks/host-management.yml @@ -29,20 +29,6 @@ when: cmk_add_host tags: cmk_register -- name: cmk_discovery - uri: - method: POST - url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}" - body: 'request={"hostname":"{{ instance_name | default(inventory_hostname) }}"}' - body_format: raw - status_code: 200 - validate_certs: no - follow_redirects: yes - become: no - when: "cmk_add_host and output.result_code == 0" - delegate_to: localhost - tags: cmk_register - - name: cmk_apply uri: method: POST diff --git a/tasks/main.yml b/tasks/main.yml index 6e36357..b86ef0b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,18 @@ --- # tasks file for ansible-role-cmk-agent + +# Include OS Variables +- include_vars: "{{ ansible_os_family }}.yml" + - include_tasks: "{{ ansible_os_family }}.yml" - meta: flush_handlers +# Add host to checkmk - include_tasks: host-management.yml when: cmk_fresh_install +# Register for automatic agent updates - include_tasks: "{{ ansible_os_family }}-register.yml" when: cmk_fresh_install +# Finalize things and collect all available services - include_tasks: host-configure.yml when: cmk_fresh_install \ No newline at end of file