fix: Also now using local_action for host config in checkmk 🐛
Some checks failed
CI / lint (push) Failing after 1m48s
CI / Molecule Test (almalinux8) (push) Has been skipped
CI / Molecule Test (almalinux9) (push) Has been skipped
CI / release (push) Has been skipped
CI / notify (push) Has been skipped

This commit is contained in:
2025-02-21 07:18:54 +13:00
parent 096655a6c1
commit 8cded0fb55
3 changed files with 135 additions and 61 deletions

View File

@@ -1,62 +1,11 @@
---
- 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: false
follow_redirects: true
become: false
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: false
follow_redirects: true
become: false
run_once: true
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: false
follow_redirects: true
become: false
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: false
follow_redirects: true
become: false
run_once: true
when: cmk_add_host and output.result_code == 0
delegate_to: localhost
tags: cmk_register
- include_tasks: host-configure/legacy.yml
when: >
cmk_add_host and
(cmk_major | int <= 2 and
cmk_minor | int < 2 or cmk_force_install)
- include_tasks: host-configure/modern.yml
when: >
cmk_add_host and
(cmk_major | int >= 2 and
cmk_minor | int >= 2 or cmk_force_install)

View File

@@ -0,0 +1,68 @@
---
- name: Output contains
debug:
var: output
- name: cmk_discovery
local_action:
module: 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: false
follow_redirects: true
become: false
when: cmk_add_host and output.id != ""
tags: cmk_register
- name: cmk_apply
local_action:
module: 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: false
follow_redirects: true
become: false
run_once: true
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
local_action:
module: 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: false
follow_redirects: true
become: false
when: cmk_add_host and output.result_code == 0
tags: cmk_register
- name: cmk_apply
local_action:
module: 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: false
follow_redirects: true
become: false
run_once: true
when: cmk_add_host and output.result_code == 0
tags: cmk_register

View File

@@ -0,0 +1,57 @@
---
- name: Output contains
debug:
var: output
- name: cmk_discovery
local_action:
module: uri
method: POST
url: "{{ cmk_api_url }}/domain-types/service_discovery_run/actions/start/invoke"
headers:
Authorization: "Bearer {{ cmk_username }} {{ cmk_secret }}"
Accept: application/json
Content-Type: application/json
body_format: raw
body: |
{
"host_name": "{{ inventory_hostname | upper }}",
"mode": "fix_all"
}
status_code: 200
validate_certs: false
follow_redirects: true
become: false
when: cmk_add_host and res_add.status != 400 and output.id != ""
tags: cmk_register
- name: Just Waiting
pause:
seconds: 20
- name: cmk_apply
local_action:
module: uri
method: POST
url: '{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/1.0/domain-types/activation_run/actions/activate-changes/invoke'
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
Accept: application/json
If-Match: "*"
body_format: json
body:
redirect: false
sites:
- "{{ cmk_omd_site }}"
force_foreign_changes: false
status_code: [200]
validate_certs: false
follow_redirects: true
become: false
run_once: true
when: cmk_add_host and res_add.status != 400 and output.id != ""
tags: cmk_register
- name: Wait some time
pause:
seconds: 10