Update register of host

This commit is contained in:
2022-08-09 07:42:02 +12:00
parent 3d39f3e231
commit 342fec8955
5 changed files with 83 additions and 23 deletions

View File

@@ -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 # adds new hosts by default to Unsorted folder
# cmk_folder: your_folder_in_WATO # cmk_folder: your_folder_in_WATO
# Copy paste the link address for rpm agent from CheckMK cmk_download_mode: samba
cmk_rpm_agent: http://url-from-your-agent-bakery-in-checkmk.rpm cmk_smb_password: ~
# Copy paste the link address for MSI (Windows) agent from CheckMK cmk_smb_username: ~
cmk_msi_agent: http://url-from-your-agent-bakery-in-checkmk.msi
# 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 # Check_MK GPG Key
# Copy paste the link address from Signature Keys for Signing Agents page # Copy paste the link address from Signature Keys for Signing Agents page

View File

@@ -1,11 +1,19 @@
- block: - block:
- name: Register with CheckMK Update Server - name: Register with CheckMK Update Server
shell: | 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 }} --secret {{ cmk_secret }}
changed_when: false changed_when: false
notify: remove agent notify: remove agent
tags: cmk_register tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register
rescue: rescue:
- name: Gather facts of packages - name: Gather facts of packages
package_facts: package_facts:
@@ -13,9 +21,10 @@
tags: cmk_register tags: cmk_register
- name: Ensure check_mk_agent installed (again) - name: Ensure check_mk_agent installed (again)
command: /usr/bin/yum install --nogpgcheck -y /tmp/check-mk-agent.rpm package:
args: name: /tmp/check-mk-agent.rpm
warn: no state: latest
skip_gpg_check: true
notify: notify:
- restart xinetd - restart xinetd
- ensure firewall open - ensure firewall open
@@ -29,9 +38,16 @@
- name: Register with CheckMK Update Server (retry) - name: Register with CheckMK Update Server (retry)
shell: | 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 }} --secret {{ cmk_secret }}
changed_when: false changed_when: false
when: "'check-mk-agent' in ansible_facts.packages" when: "'check-mk-agent' in ansible_facts.packages"
notify: remove agent notify: remove agent
tags: cmk_register tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register

View File

@@ -1,4 +1,5 @@
--- ---
- name: cmk_discovery - name: cmk_discovery
uri: uri:
method: POST method: POST
@@ -27,3 +28,36 @@
when: "cmk_add_host and output.result_code == 0" when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost delegate_to: localhost
tags: cmk_register 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

View File

@@ -29,20 +29,6 @@
when: cmk_add_host when: cmk_add_host
tags: cmk_register 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 - name: cmk_apply
uri: uri:
method: POST method: POST

View File

@@ -1,11 +1,18 @@
--- ---
# tasks file for ansible-role-cmk-agent # tasks file for ansible-role-cmk-agent
# Include OS Variables
- include_vars: "{{ ansible_os_family }}.yml"
- include_tasks: "{{ ansible_os_family }}.yml" - include_tasks: "{{ ansible_os_family }}.yml"
- meta: flush_handlers - meta: flush_handlers
# Add host to checkmk
- include_tasks: host-management.yml - include_tasks: host-management.yml
when: cmk_fresh_install when: cmk_fresh_install
# Register for automatic agent updates
- include_tasks: "{{ ansible_os_family }}-register.yml" - include_tasks: "{{ ansible_os_family }}-register.yml"
when: cmk_fresh_install when: cmk_fresh_install
# Finalize things and collect all available services
- include_tasks: host-configure.yml - include_tasks: host-configure.yml
when: cmk_fresh_install when: cmk_fresh_install