fix: Use local_action to ensure runs on controller 🐛

This commit is contained in:
2025-02-21 07:13:00 +13:00
parent a49fcd4daa
commit 096655a6c1
2 changed files with 13 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
---
- name: Retrieve checkmk version
uri:
local_action:
module: uri
method: GET
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}

View File

@@ -1,6 +1,7 @@
---
- name: add host to omd (new)
uri:
local_action:
module: uri
method: POST
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
@@ -18,7 +19,6 @@
status_code: [200, 400]
register: res_add
become: false
delegate_to: localhost
when: >
cmk_add_host and cmk_major | int >= 2 and cmk_minor | int >= 2
@@ -28,7 +28,9 @@
when: cmk_add_host
- name: Host exists fetch etag (new) # noqa command-instead-of-module
shell: |
local_action:
module: shell
cmd: |
curl \
-G \
-i \
@@ -39,7 +41,6 @@
"{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/v0/objects/host_config/{{ inventory_hostname | upper }}"
register: res_host_exists
become: false
delegate_to: localhost
when: >
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
(res_add.status == 400 and output.fields.host_name | first | regex_search('already
@@ -54,7 +55,8 @@
exists.$'))
- name: Update host as already exists? (new)
uri:
local_action:
module: uri
method: PUT
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
@@ -70,7 +72,6 @@
status_code: [200]
register: res
become: false
delegate_to: localhost
when: >
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
(res_add.status == 400 and output.fields.host_name | first | regex_search('already
@@ -82,7 +83,8 @@
when: cmk_add_host
- name: cmk_discovery (new)
uri:
local_action:
module: uri
method: POST
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
@@ -98,10 +100,10 @@
cmk_add_host and cmk_major | int >= 2 and
cmk_minor | int >= 2 or
cmk_force_install
delegate_to: localhost
- name: cmk_apply (new)
uri:
local_action:
module: uri
method: POST
headers:
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
@@ -120,4 +122,3 @@
when: >
cmk_add_host and cmk_major | int >= 2 and
cmk_minor | int >= 2 or cmk_force_install
delegate_to: localhost