From b2978de8b13b1a00bee63f1c5974f36b6d69c017 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 19:26:37 +0100 Subject: [PATCH 001/117] init: draft --- plugins/modules/host.py | 542 +++++++++++++++++++++++++--------------- 1 file changed, 345 insertions(+), 197 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 1be564dd0..8dda18d18 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -36,26 +36,35 @@ B(Attention! This option OVERWRITES all existing attributes!) If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw - default: {} + required: false update_attributes: description: - The update_attributes of your host as described in the API documentation. This will only update the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw - default: {} + required: false remove_attributes: description: - The remove_attributes of your host as described in the API documentation. + B(If a list of strings is supplied, the listed attributes are removed.) + B(If extended_functionality and a dict is supplied, the attributes that exactly match + the passed attributes are removed.) This will only remove the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). + As of Check MK v2.2.0p7 and v2.3.0b1, simultaneous use of I(attributes), + I(remove_attributes), and I(update_attributes) is no longer supported. type: raw - default: [] + required: false state: description: The state of your host. type: str default: present choices: [present, absent] + extended_functionality: + description: Allow extended functionality instead of the expected REST API behavior. + type: bool + default: true author: - Robin Gierse (@robin-checkmk) @@ -163,149 +172,350 @@ import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.dict_transformations import dict_merge +from ansible.module_utils.common.dict_transformations import dict_merge, recursive_diff from ansible.module_utils.common.validation import check_type_list -from ansible.module_utils.urls import fetch_url +from ansible_collections.checkmk.general.plugins.module_utils.api import CheckmkAPI +from ansible_collections.checkmk.general.plugins.module_utils.types import RESULT +from ansible_collections.checkmk.general.plugins.module_utils.utils import ( + result_as_dict, +) +from ansible_collections.checkmk.general.plugins.module_utils.version import ( + CheckmkVersion, +) + +HOST = ( + "customer", + "attributes", + "update_attributes", + "remove_attributes", +) + +HOST_PARENTS_PARSE = ( + "attributes", + "update_attributes", +) + + +class HostHTTPCodes: + # http_code: (changed, failed, "Message") + get = { + 200: (False, False, "Host found, nothing changed"), + 404: (False, False, "Host not found"), + } + + create = {200: (True, False, "Host created")} + edit = {200: (True, False, "Host modified")} + edit = {200: (True, False, "Host moved")} + delete = {204: (True, False, "Host deleted")} + + +class HostEndpoints: + default = "/objects/host_config" + create = "/domain-types/host_config/collections/all" + + +class HostAPI(CheckmkAPI): + def __init__(self, module): + super().__init__(module) + + self.extended_functionality = self.params.get("extended_functionality", True) + self.desired = {} -def exit_failed(module, msg): - result = {"msg": msg, "changed": False, "failed": True} - module.fail_json(**result) + self.desired["folder"] = self.params.get("folder", "/") + self.desired["host_name"] = self.params.get("name") -def exit_changed(module, msg): - result = {"msg": msg, "changed": True, "failed": False} - module.exit_json(**result) + for key in HOST: + if self.params.get(key): + self.desired[key] = self.params.get(key) + for key in HOST_PARENTS_PARSE: + if self.desired.get(key): + if self.desired.get(key).get("parents"): + self.desired[key]["parents"] = check_type_list( + self.desired.get(key).get("parents") + ) -def exit_ok(module, msg): - result = {"msg": msg, "changed": False, "failed": False} - module.exit_json(**result) + # Get the current host from the API and set some parameters + self._get_current() + self._changed_items = self._detect_changes() + self._verify_compatibility() -def get_current_host_state(module, base_url, headers): - current_state = "unknown" - current_explicit_attributes = {} - current_folder = "/" - etag = "" + def _verify_compatibility(self): + # Check if parameters are compatible with CMK version + if ( + sum( + [ + 1 + for el in ["attributes", "remove_attributes", "update_attributes"] + if self.module.params.get(el) + ] + ) + > 1 + ): + + ver = self.getversion() + msg = ( + "As of Check MK v2.2.0p7 and v2.3.0b1, simultaneous use of" + " attributes, remove_attributes, and update_attributes is no longer supported." + ) - api_endpoint = "/objects/host_config/" + module.params.get("name") - parameters = "?effective_attributes=true" - url = base_url + api_endpoint + parameters + if ver >= CheckmkVersion("2.2.0p7"): + result = RESULT( + http_code=0, + msg=msg, + content="", + etag="", + failed=True, + changed=False, + ) + self.module.exit_json(**result_as_dict(result)) + else: + self.module.warn(msg) - response, info = fetch_url(module, url, data=None, headers=headers, method="GET") + def _normalize_folder(self, folder): + if folder in ["", " ", "/", "//"]: + return "/" - if info["status"] == 200: - body = json.loads(response.read()) - current_state = "present" - etag = info.get("etag", "") - extensions = body.get("extensions", {}) - current_explicit_attributes = extensions.get("attributes", {}) - current_folder = "%s" % extensions.get("folder", "/") - if "meta_data" in current_explicit_attributes: - del current_explicit_attributes["meta_data"] + if not folder.startswith("/"): + folder = "/%s" % folder - elif info["status"] == 404: - current_state = "absent" + if folder.endswith("/"): + folder = folder.rstrip("/") - else: - exit_failed( - module, - "Error calling API. HTTP code %d. Details: %s." - % (info["status"], info.get("body", "N/A")), + return folder + + def _build_default_endpoint(self): + return "%s/%s" % ( + HostEndpoints.default, + self.desired["host_name"], ) - return current_state, current_explicit_attributes, current_folder, etag + def _build_move_endpoint(self): + return "%s/%s/actions/move/invoke" % ( + HostEndpoints.default, + self.desired["host_name"], + ) + ### + def _detect_changes(self): + current_attributes = self.current.get("attributes", {}) + desired_attributes = self.desired.copy() + changes = [] -def set_host_attributes(module, attributes, base_url, headers, update_method): - api_endpoint = "/objects/host_config/" + module.params.get("name") - params = { - update_method: attributes, - } - url = base_url + api_endpoint + if desired_attributes.get("update_attributes"): + merged_attributes = dict_merge( + current_attributes, desired_attributes.get("update_attributes") + ) - response, info = fetch_url( - module, url, module.jsonify(params), headers=headers, method="PUT" - ) + if merged_attributes != current_attributes: + try: + (c_m, m_c) = recursive_diff(current_attributes, merged_attributes) + changes.append("update attributes: %s" % json.dumps(m_c)) + except Exception as e: + changes.append("update attributes") + desired_attributes["update_attributes"] = merged_attributes + + if desired_attributes.get( + "attributes" + ) and current_attributes != desired_attributes.get("attributes"): + changes.append("attributes") + + if self.current.get("folder") != desired_attributes.get("folder"): + changes.append("folder") + + if desired_attributes.get("remove_attributes"): + tmp_remove_attributes = desired_attributes.get("remove_attributes") + + if isinstance(tmp_remove_attributes, list): + removes_which = [ + a for a in tmp_remove_attributes if current_attributes.get(a) + ] + if len(removes_which) > 0: + changes.append("remove attributes: %s" % " ".join(removes_which)) + elif isinstance(tmp_remove_attributes, dict): + if not self.extended_functionality: + self.module.fail_json( + msg="ERROR: The parameter remove_attributes of dict type is not supported for the paramter extended_functionality: false!", + ) + + (tmp_remove, tmp_rest) = (current_attributes, {}) + if current_attributes != tmp_remove_attributes: + try: + (c_m, m_c) = recursive_diff( + current_attributes, tmp_remove_attributes + ) + + if c_m: + # if nothing to remove + if current_attributes == c_m: + (tmp_remove, tmp_rest) = ({}, current_attributes) + else: + (c_c_m, c_m_c) = recursive_diff(current_attributes, c_m) + (tmp_remove, tmp_rest) = (c_c_m, c_m) + except Exception as e: + self.module.fail_json( + msg="ERROR: incompatible parameter: remove_attributes!", + exception=e, + ) + + desired_attributes.pop("remove_attributes") + if tmp_remove != {}: + changes.append("remove attributes: %s" % json.dumps(tmp_remove)) + if tmp_rest != {}: + desired_attributes["update_attributes"] = tmp_rest + else: + self.module.fail_json( + msg="ERROR: The parameter remove_attributes can be a list of strings or a dictionary!", + exception=e, + ) + + if self.extended_functionality: + self.desired = desired_attributes.copy() - if info["status"] == 400 and update_method == "remove_attributes": - return "Host attributes allready removed." - elif info["status"] != 200: - exit_failed( - module, - "Error calling API. HTTP code %d. Details: %s, " - % (info["status"], info["body"]), + # self.module.fail_json(json.dumps(desired_attributes)) + + return changes + + ### + def _get_current(self): + result = self._fetch( + code_mapping=HostHTTPCodes.get, + endpoint=self._build_default_endpoint(), + method="GET", ) + if result.http_code == 200: + self.state = "present" -def move_host(module, base_url, headers): - api_endpoint = "/objects/host_config/%s/actions/move/invoke" % module.params.get( - "name" - ) - params = { - "target_folder": module.params.get("folder", "/"), - } - url = base_url + api_endpoint + content = json.loads(result.content) - response, info = fetch_url( - module, url, module.jsonify(params), headers=headers, method="POST" - ) + extensions = content["extensions"] + self.current["folder"] = extentions.pop("folder", "/") + for key, value in extensions.items(): + if key == "attributes": + value.pop("meta_data") + if "network_scan_results" in value: + value.pop("network_scan_results") + self.current[key] = value - if info["status"] != 200: - exit_failed( - module, - "Error calling API. HTTP code %d. Details: %s, " - % (info["status"], info["body"]), + self.etag = result.etag + + else: + self.state = "absent" + + def _check_output(self, mode): + return RESULT( + http_code=0, + msg="Running in check mode. Would have done an %s" % mode, + content="", + etag="", + failed=False, + changed=False, ) + ### + def needs_update(self): + return len(self._changed_items) > 0 -def create_host(module, attributes, base_url, headers): - api_endpoint = "/domain-types/host_config/collections/all" - params = { - "folder": module.params.get("folder", "/"), - "host_name": module.params.get("name"), - "attributes": attributes, - } - url = base_url + api_endpoint + ### + def create(self): + data = self.desired.copy() + if data.get("attributes", {}) == {}: + data["attributes"] = data.pop("update_attributes", {}) - response, info = fetch_url( - module, url, module.jsonify(params), headers=headers, method="POST" - ) + if data.get("remove_attributes"): + data.pop("remove_attributes") + + if self.module.check_mode: + return self._check_output("create") - if info["status"] != 200: - exit_failed( - module, - "Error calling API. HTTP code %d. Details: %s, " - % (info["status"], info["body"]), + result = self._fetch( + code_mapping=HostHTTPCodes.create, + endpoint=HostEndpoints.create, + data=data, + method="POST", ) + return result -def delete_host(module, base_url, headers): - api_endpoint = "/objects/host_config/" + module.params.get("name") - url = base_url + api_endpoint + def edit(self): + data = self.desired.copy() + data.pop("host_name") - response, info = fetch_url(module, url, data=None, headers=headers, method="DELETE") + tmp = {} + tmp["target_folder"] = data.pop("folder", "/") + self.headers["if-Match"] = self.etag - if info["status"] != 204: - exit_failed( - module, - "Error calling API. HTTP code %d. Details: %s, " - % (info["status"], info["body"]), + if self.module.check_mode: + return self._check_output("edit") + + result = self._fetch( + code_mapping=HostHTTPCodes.move, + endpoint=self._build_move_endpoint(), + data=tmp, + method="POST", + ) + + result._replace( + msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) + if self.module.check_mode: + return self._check_output("edit") + + if data.get("update_attributes") == {}: + data.pop("update_attributes") + + if data.get("remove_attributes") == []: + data.pop("remove_attributes") + + if data.get("update_attributes") and data.get("remove_attributes"): + tmp = data.copy() + tmp.pop("remove_attributes") + self.module.fail_json(json.dumps(tmp)) + result = self._fetch( + code_mapping=HostHTTPCodes.edit, + endpoint=self._build_default_endpoint(), + data=tmp, + method="PUT", + ) + + tmp = data.copy() + tmp.pop("update_attributes") + result = self._fetch( + code_mapping=HostHTTPCodes.edit, + endpoint=self._build_default_endpoint(), + data=tmp, + method="PUT", + ) + else: + data["update_method"] = data.pop("update_attributes") -def normalize_folder(folder): - if folder in ["", " ", "/", "//"]: - return "/" + result = self._fetch( + code_mapping=FolderHTTPCodes.edit, + endpoint=self._build_default_endpoint(), + data=data, + method="PUT", + ) - if not folder.startswith("/"): - folder = "/%s" % folder + return result._replace( + msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) + ) + + def delete(self): + if self.module.check_mode: + return self._check_output("delete") - if folder.endswith("/"): - folder = folder.rstrip("/") + result = self._fetch( + code_mapping=HostHTTPCodes.delete, + endpoint=self._build_default_endpoint(), + method="DELETE", + ) - return folder + return result def run_module(): @@ -320,106 +530,44 @@ def run_module(): type="str", required=True, ), - attributes=dict(type="raw", default={}), - remove_attributes=dict(type="raw", default=[]), - update_attributes=dict(type="raw", default={}), + attributes=dict(type="raw", required=False), + remove_attributes=dict(type="raw", required=False), + update_attributes=dict(type="raw", required=False), folder=dict(type="str", required=False), state=dict(type="str", default="present", choices=["present", "absent"]), + extended_functionality=dict(type="bool", required=False, default=True), ) - module = AnsibleModule(argument_spec=module_args, supports_check_mode=False) + module = AnsibleModule(argument_spec=module_args, supports_check_mode=True) - # Use the parameters to initialize some common variables - headers = { - "Accept": "application/json", - "Content-Type": "application/json", - "Authorization": "Bearer %s %s" - % ( - module.params.get("automation_user", ""), - module.params.get("automation_secret", ""), - ), - } + # Create an API object that contains the current and desired state + current_host = HostAPI(module) - base_url = "%s/%s/check_mk/api/1.0" % ( - module.params.get("server_url", ""), - module.params.get("site", ""), + result = RESULT( + http_code=0, + msg="No changes needed.", + content="", + etag="", + failed=False, + changed=False, ) - # Determine desired state and attributes - attributes = module.params.get("attributes", {}) - remove_attributes = module.params.get("remove_attributes", []) - update_attributes = module.params.get("update_attributes", {}) - state = module.params.get("state", "present") - - for par in [attributes, update_attributes]: - if par != {}: - if par.get("parents"): - par["parents"] = check_type_list(par.get("parents")) - - if module.params["folder"]: - module.params["folder"] = normalize_folder(module.params["folder"]) - - # Determine the current state of this particular host - ( - current_state, - current_explicit_attributes, - current_folder, - etag, - ) = get_current_host_state(module, base_url, headers) - - # Handle the host accordingly to above findings and desired state - if state == "present" and current_state == "present": - headers["If-Match"] = etag - msg_tokens = [] - - current_folder = normalize_folder(current_folder) - merged_attributes = dict_merge(current_explicit_attributes, update_attributes) - - if module.params["folder"] and current_folder != module.params["folder"]: - move_host(module, base_url, headers) - msg_tokens.append("Host was moved.") - - if attributes != {} and current_explicit_attributes != attributes: - set_host_attributes(module, attributes, base_url, headers, "attributes") - msg_tokens.append("Host attributes replaced.") - - if update_attributes != {} and current_explicit_attributes != merged_attributes: - set_host_attributes( - module, merged_attributes, base_url, headers, "attributes" - ) - msg_tokens.append("Host attributes updated.") - - if remove_attributes != []: - msg = set_host_attributes( - module, remove_attributes, base_url, headers, "remove_attributes" - ) - if msg == "Host attributes allready removed.": - exit_ok(module, msg) - else: - msg_tokens.append("Host attributes removed.") - - if len(msg_tokens) >= 1: - exit_changed(module, " ".join(msg_tokens)) - else: - exit_ok(module, "Host already present. All explicit attributes as desired.") - - elif state == "present" and current_state == "absent": - if update_attributes != {} and attributes == {}: - attributes = update_attributes - if not module.params["folder"]: - module.params["folder"] = "/" - create_host(module, attributes, base_url, headers) - exit_changed(module, "Host created.") - - elif state == "absent" and current_state == "absent": - exit_ok(module, "Host already absent.") - - elif state == "absent" and current_state == "present": - delete_host(module, base_url, headers) - exit_changed(module, "Host deleted.") - - else: - exit_failed(module, "Unknown error") + desired_state = current_host.params.get("state") + if current_host.state == "present": + result = result._replace( + msg="Host already exists with the desired parameters." + ) + if desired_state == "absent": + result = current_host.delete() + elif current_host.needs_update(): + move + result = current_host.edit() + elif current_host.state == "absent": + result = result._replace(msg="Folder already absent.") + if desired_state in ("present"): + result = current_host.create() + + module.exit_json(**result_as_dict(result)) def main(): From 6e4b799f125bcfd262663c1c41bb1ebd08c4f998 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 19:32:30 +0100 Subject: [PATCH 002/117] fix: --- plugins/modules/host.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 8dda18d18..c25543525 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -393,7 +393,7 @@ def _get_current(self): content = json.loads(result.content) extensions = content["extensions"] - self.current["folder"] = extentions.pop("folder", "/") + self.current["folder"] = extensions.pop("folder", "/") for key, value in extensions.items(): if key == "attributes": value.pop("meta_data") @@ -459,9 +459,7 @@ def edit(self): method="POST", ) - result._replace( - msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") - ) + result._replace(msg=result.msg + ". Moved to: %s" % tmp.get("target_folder")) if self.module.check_mode: return self._check_output("edit") @@ -495,7 +493,7 @@ def edit(self): data["update_method"] = data.pop("update_attributes") result = self._fetch( - code_mapping=FolderHTTPCodes.edit, + code_mapping=HostHTTPCodes.edit, endpoint=self._build_default_endpoint(), data=data, method="PUT", @@ -554,13 +552,10 @@ def run_module(): desired_state = current_host.params.get("state") if current_host.state == "present": - result = result._replace( - msg="Host already exists with the desired parameters." - ) + result = result._replace(msg="Host already exists with the desired parameters.") if desired_state == "absent": result = current_host.delete() elif current_host.needs_update(): - move result = current_host.edit() elif current_host.state == "absent": result = result._replace(msg="Folder already absent.") From d113f6ddcb661cc7b06b8eaa79c3938c12bfd6ea Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 19:48:15 +0100 Subject: [PATCH 003/117] fix: --- plugins/modules/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index c25543525..3da6380f0 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -393,7 +393,7 @@ def _get_current(self): content = json.loads(result.content) extensions = content["extensions"] - self.current["folder"] = extensions.pop("folder", "/") + self.current["folder"] = extensions.get("folder", "/") for key, value in extensions.items(): if key == "attributes": value.pop("meta_data") @@ -446,7 +446,7 @@ def edit(self): data.pop("host_name") tmp = {} - tmp["target_folder"] = data.pop("folder", "/") + tmp["target_folder"] = data.get("folder", "/") self.headers["if-Match"] = self.etag if self.module.check_mode: From 19dbad02ad854ff5d0139b46c5968175fec891f3 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 20:00:21 +0100 Subject: [PATCH 004/117] fix: --- plugins/modules/host.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 3da6380f0..aa7504b93 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -222,8 +222,6 @@ def __init__(self, module): self.desired = {} - self.desired["folder"] = self.params.get("folder", "/") - self.desired["host_name"] = self.params.get("name") for key in HOST: @@ -239,6 +237,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() + self.desired["folder"] = self.params.get("folder", self.desired.get("folder", "/")) self._changed_items = self._detect_changes() self._verify_compatibility() From b47ba1032ddef93d83babe4accfe7bbabf315966 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 20:01:26 +0100 Subject: [PATCH 005/117] fix: style --- plugins/modules/host.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index aa7504b93..1691da299 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -237,7 +237,9 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - self.desired["folder"] = self.params.get("folder", self.desired.get("folder", "/")) + self.desired["folder"] = self.params.get( + "folder", self.desired.get("folder", "/") + ) self._changed_items = self._detect_changes() self._verify_compatibility() From 4ace5cd9a5bc90a1ff92bba15f46ad8e5bc96624 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 20:15:11 +0100 Subject: [PATCH 006/117] fix: folder --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 1691da299..4992b0908 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -238,7 +238,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() self.desired["folder"] = self.params.get( - "folder", self.desired.get("folder", "/") + "folder", self.current.get("folder", "/") ) self._changed_items = self._detect_changes() From 1762edbab4f13ad0cbfab9b73d2f739b644595dd Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 20:48:42 +0100 Subject: [PATCH 007/117] fix: folder --- plugins/modules/host.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 4992b0908..a94ca9a3f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -184,7 +184,6 @@ ) HOST = ( - "customer", "attributes", "update_attributes", "remove_attributes", @@ -237,9 +236,11 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - self.desired["folder"] = self.params.get( - "folder", self.current.get("folder", "/") - ) + tmp_folder = self.params.get("folder") + if not tmp_folder: + tmp_folder = self.current.get("folder", "/") + self.desired["folder"] = tmp_folder + module.fail_json(json.dumps(self.desired)) self._changed_items = self._detect_changes() self._verify_compatibility() From fb805a4515d3113c5f26ba6d3fda23eced8b6b39 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:11:16 +0100 Subject: [PATCH 008/117] rempove: printout --- plugins/modules/host.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index a94ca9a3f..8f74b6eca 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -240,7 +240,6 @@ def __init__(self, module): if not tmp_folder: tmp_folder = self.current.get("folder", "/") self.desired["folder"] = tmp_folder - module.fail_json(json.dumps(self.desired)) self._changed_items = self._detect_changes() self._verify_compatibility() From f4426e8cdcbb3c0ec172de7a9eccd2e9a451ba25 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:16:29 +0100 Subject: [PATCH 009/117] fix: --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 8f74b6eca..a67dc3d32 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -204,7 +204,7 @@ class HostHTTPCodes: create = {200: (True, False, "Host created")} edit = {200: (True, False, "Host modified")} - edit = {200: (True, False, "Host moved")} + move = {200: (True, False, "Host moved")} delete = {204: (True, False, "Host deleted")} From fb60e85e32500997246dbe3da0968bece02c5e3c Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:26:07 +0100 Subject: [PATCH 010/117] test: concept --- plugins/modules/host.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index a67dc3d32..d52d47fb1 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -300,7 +300,6 @@ def _build_move_endpoint(self): self.desired["host_name"], ) - ### def _detect_changes(self): current_attributes = self.current.get("attributes", {}) desired_attributes = self.desired.copy() @@ -380,7 +379,6 @@ def _detect_changes(self): return changes - ### def _get_current(self): result = self._fetch( code_mapping=HostHTTPCodes.get, @@ -417,11 +415,9 @@ def _check_output(self, mode): changed=False, ) - ### def needs_update(self): return len(self._changed_items) > 0 - ### def create(self): data = self.desired.copy() if data.get("attributes", {}) == {}: @@ -446,21 +442,23 @@ def edit(self): data = self.desired.copy() data.pop("host_name") - tmp = {} - tmp["target_folder"] = data.get("folder", "/") self.headers["if-Match"] = self.etag if self.module.check_mode: return self._check_output("edit") - result = self._fetch( - code_mapping=HostHTTPCodes.move, - endpoint=self._build_move_endpoint(), - data=tmp, - method="POST", - ) + if self.current.get("folder") != data.get("folder", "/"): + tmp = {} + tmp["target_folder"] = data.get("folder", "/") + + result = self._fetch( + code_mapping=HostHTTPCodes.move, + endpoint=self._build_move_endpoint(), + data=tmp, + method="POST", + ) - result._replace(msg=result.msg + ". Moved to: %s" % tmp.get("target_folder")) + result._replace(msg=result.msg + ". Moved to: %s" % tmp.get("target_folder")) if self.module.check_mode: return self._check_output("edit") From 109356f5d6f886c7d581100aacf7102d464e94cd Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:36:02 +0100 Subject: [PATCH 011/117] fix: --- plugins/modules/host.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index d52d47fb1..e0a540c88 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -458,7 +458,9 @@ def edit(self): method="POST", ) - result._replace(msg=result.msg + ". Moved to: %s" % tmp.get("target_folder")) + result._replace( + msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") + ) if self.module.check_mode: return self._check_output("edit") @@ -489,8 +491,6 @@ def edit(self): method="PUT", ) else: - data["update_method"] = data.pop("update_attributes") - result = self._fetch( code_mapping=HostHTTPCodes.edit, endpoint=self._build_default_endpoint(), From 06fbf286538818b31a35f13aaf4c042412f0f6e5 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:43:41 +0100 Subject: [PATCH 012/117] fix: remove folder --- plugins/modules/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e0a540c88..98f812291 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -392,7 +392,7 @@ def _get_current(self): content = json.loads(result.content) extensions = content["extensions"] - self.current["folder"] = extensions.get("folder", "/") + self.current["folder"] = extensions.pop("folder", "/") for key, value in extensions.items(): if key == "attributes": value.pop("meta_data") @@ -449,7 +449,7 @@ def edit(self): if self.current.get("folder") != data.get("folder", "/"): tmp = {} - tmp["target_folder"] = data.get("folder", "/") + tmp["target_folder"] = data.pop("folder", "/") result = self._fetch( code_mapping=HostHTTPCodes.move, From 68613fa6ff11be34e4af9b92ef49d83dff7f4a71 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 21:49:32 +0100 Subject: [PATCH 013/117] fix: remove folder --- plugins/modules/host.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 98f812291..f9013bd1a 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -461,6 +461,8 @@ def edit(self): result._replace( msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) + else: + data.pop("folder") if self.module.check_mode: return self._check_output("edit") From 3f372ac0ad6d4c378926bf09e73016f808922b99 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 22:05:20 +0100 Subject: [PATCH 014/117] refactor: --- plugins/modules/host.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index f9013bd1a..51dfc2d00 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -223,6 +223,8 @@ def __init__(self, module): self.desired["host_name"] = self.params.get("name") + tmp_folder = self.params.get("folder", "/") + for key in HOST: if self.params.get(key): self.desired[key] = self.params.get(key) @@ -236,10 +238,10 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - tmp_folder = self.params.get("folder") - if not tmp_folder: - tmp_folder = self.current.get("folder", "/") - self.desired["folder"] = tmp_folder + + if tmp_folder != self.current.get("folder", "/") + self.desired["folder"] = tmp_folder + self._changed_items = self._detect_changes() self._verify_compatibility() @@ -323,7 +325,7 @@ def _detect_changes(self): ) and current_attributes != desired_attributes.get("attributes"): changes.append("attributes") - if self.current.get("folder") != desired_attributes.get("folder"): + if desired_attributes.get("folder") and self.current.get("folder") != desired_attributes.get("folder"): changes.append("folder") if desired_attributes.get("remove_attributes"): @@ -447,10 +449,10 @@ def edit(self): if self.module.check_mode: return self._check_output("edit") - if self.current.get("folder") != data.get("folder", "/"): - tmp = {} - tmp["target_folder"] = data.pop("folder", "/") + if data.get("folder"): + tmp = {} + tmp["target_folder"] = data.pop("folder") result = self._fetch( code_mapping=HostHTTPCodes.move, endpoint=self._build_move_endpoint(), @@ -461,8 +463,6 @@ def edit(self): result._replace( msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) - else: - data.pop("folder") if self.module.check_mode: return self._check_output("edit") From 009a9810f8166799935010c1d6ba565eb4aa08fa Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 22:06:35 +0100 Subject: [PATCH 015/117] fix: --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 51dfc2d00..0e1248998 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -239,7 +239,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if tmp_folder != self.current.get("folder", "/") + if tmp_folder != self.current.get("folder", "/"): self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() From 6ca18ec88e3c90489db743e21e05722fe8dfa896 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 22:15:05 +0100 Subject: [PATCH 016/117] add: default folder --- plugins/modules/host.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 0e1248998..f5da93c95 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -325,7 +325,9 @@ def _detect_changes(self): ) and current_attributes != desired_attributes.get("attributes"): changes.append("attributes") - if desired_attributes.get("folder") and self.current.get("folder") != desired_attributes.get("folder"): + if desired_attributes.get("folder") and self.current.get( + "folder" + ) != desired_attributes.get("folder"): changes.append("folder") if desired_attributes.get("remove_attributes"): @@ -428,6 +430,9 @@ def create(self): if data.get("remove_attributes"): data.pop("remove_attributes") + if data.get("folder"): + data["folder"] = "/" + if self.module.check_mode: return self._check_output("create") @@ -449,7 +454,6 @@ def edit(self): if self.module.check_mode: return self._check_output("edit") - if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") From bc62d81d89584d5234571add96aae6357009e9b3 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 22:33:33 +0100 Subject: [PATCH 017/117] fix: folder field --- plugins/modules/host.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index f5da93c95..a3dc7c2eb 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -223,8 +223,6 @@ def __init__(self, module): self.desired["host_name"] = self.params.get("name") - tmp_folder = self.params.get("folder", "/") - for key in HOST: if self.params.get(key): self.desired[key] = self.params.get(key) @@ -239,8 +237,10 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if tmp_folder != self.current.get("folder", "/"): - self.desired["folder"] = tmp_folder + if not self.current.get("folder"): + self.desired["folder"] = self.params.get("folder", '/') + elif self.params.get("folder") and self.params.get("folder") != self.current.get("folder"): + self.desired["folder"] = self.params.get("folder") self._changed_items = self._detect_changes() From 94181a7294d74863224478314e76c84f66bfc9da Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 22:47:35 +0100 Subject: [PATCH 018/117] fix: folder field --- plugins/modules/host.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index a3dc7c2eb..e334b047f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -238,8 +238,13 @@ def __init__(self, module): self._get_current() if not self.current.get("folder"): - self.desired["folder"] = self.params.get("folder", '/') - elif self.params.get("folder") and self.params.get("folder") != self.current.get("folder"): + if self.params.get("folder"): + self.desired["folder"] = self.params.get("folder") + else: + self.desired["folder"] = "/" + elif self.params.get("folder") and self.params.get( + "folder" + ) != self.current.get("folder"): self.desired["folder"] = self.params.get("folder") self._changed_items = self._detect_changes() From 96d28f9a6ad4e923a51e6da2b239c65fa6ed9557 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 23:21:31 +0100 Subject: [PATCH 019/117] fix: folder field --- plugins/modules/host.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e334b047f..0ada51813 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -237,15 +237,15 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() + if self.params.get("folder"): + tmp_folder = self._normalize_folder(self.params.get("folder")) + else: + tmp_folder = "/" + if not self.current.get("folder"): - if self.params.get("folder"): - self.desired["folder"] = self.params.get("folder") - else: - self.desired["folder"] = "/" - elif self.params.get("folder") and self.params.get( - "folder" - ) != self.current.get("folder"): - self.desired["folder"] = self.params.get("folder") + self.desired["folder"] = tmp_folder + elif self.params.get("folder") and tmp_folder != self.current.get("folder"): + self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() @@ -284,7 +284,7 @@ def _verify_compatibility(self): self.module.warn(msg) def _normalize_folder(self, folder): - if folder in ["", " ", "/", "//"]: + if folder and folder in ["", " ", "/", "//"]: return "/" if not folder.startswith("/"): From b1a461dcd814bd622e4796cda23db42abbae6ce8 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 23:35:21 +0100 Subject: [PATCH 020/117] test --- plugins/modules/host.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 0ada51813..8fa6e5107 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -462,16 +462,17 @@ def edit(self): if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") - result = self._fetch( - code_mapping=HostHTTPCodes.move, - endpoint=self._build_move_endpoint(), - data=tmp, - method="POST", - ) + if self.current.get(folder) != tmp.get("target_folder"): + result = self._fetch( + code_mapping=HostHTTPCodes.move, + endpoint=self._build_move_endpoint(), + data=tmp, + method="POST", + ) - result._replace( - msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") - ) + result._replace( + msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") + ) if self.module.check_mode: return self._check_output("edit") From f4e5e2a3da3ffae2bfa7e95e786992f75ec22253 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 23:37:14 +0100 Subject: [PATCH 021/117] test --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 8fa6e5107..e2c7344f7 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -462,7 +462,7 @@ def edit(self): if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") - if self.current.get(folder) != tmp.get("target_folder"): + if self.current.get("folder") != tmp.get("target_folder"): result = self._fetch( code_mapping=HostHTTPCodes.move, endpoint=self._build_move_endpoint(), From f6eac7fcb6d64f617a6336c5f1bfb89b54b4e991 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sat, 17 Feb 2024 23:59:17 +0100 Subject: [PATCH 022/117] fix: folder treatment --- plugins/modules/host.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e2c7344f7..bbba8707e 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -242,9 +242,7 @@ def __init__(self, module): else: tmp_folder = "/" - if not self.current.get("folder"): - self.desired["folder"] = tmp_folder - elif self.params.get("folder") and tmp_folder != self.current.get("folder"): + if not self.current.get("folder") or (self.params.get("folder") and tmp_folder != self.current.get("folder")): self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() @@ -330,7 +328,7 @@ def _detect_changes(self): ) and current_attributes != desired_attributes.get("attributes"): changes.append("attributes") - if desired_attributes.get("folder") and self.current.get( + if desired_attributes.get("folder") and self.current.get("folder") and self.current.get( "folder" ) != desired_attributes.get("folder"): changes.append("folder") From 8045eddf3e1634b41c606f9f566b1749c405b4d2 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 00:26:48 +0100 Subject: [PATCH 023/117] fix: folder treatment --- plugins/modules/host.py | 47 ++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index bbba8707e..7f77eb08f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -237,12 +237,23 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if self.params.get("folder"): - tmp_folder = self._normalize_folder(self.params.get("folder")) + if self.current.get("folder"): + if self.params.get("folder"): + tmp_folder = self._normalize_folder(self.params.get("folder")) + if tmp_folder != self.current.get("folder"): + self.desired["folder"] = tmp_folder + else: + if self.current.get("folder") != "/": + self.desired["folder"] = "/" else: - tmp_folder = "/" + if self.params.get("folder"): + self.desired["folder"] = self._normalize_folder(self.params.get("folder")) + else: + self.desired["folder"] = "/" - if not self.current.get("folder") or (self.params.get("folder") and tmp_folder != self.current.get("folder")): + if not self.current.get("folder") or ( + self.params.get("folder") and tmp_folder != self.current.get("folder") + ): self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() @@ -328,9 +339,11 @@ def _detect_changes(self): ) and current_attributes != desired_attributes.get("attributes"): changes.append("attributes") - if desired_attributes.get("folder") and self.current.get("folder") and self.current.get( - "folder" - ) != desired_attributes.get("folder"): + if ( + desired_attributes.get("folder") + and self.current.get("folder") + and self.current.get("folder") != desired_attributes.get("folder") + ): changes.append("folder") if desired_attributes.get("remove_attributes"): @@ -460,17 +473,17 @@ def edit(self): if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") - if self.current.get("folder") != tmp.get("target_folder"): - result = self._fetch( - code_mapping=HostHTTPCodes.move, - endpoint=self._build_move_endpoint(), - data=tmp, - method="POST", - ) - result._replace( - msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") - ) + result = self._fetch( + code_mapping=HostHTTPCodes.move, + endpoint=self._build_move_endpoint(), + data=tmp, + method="POST", + ) + + result._replace( + msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") + ) if self.module.check_mode: return self._check_output("edit") From 02f16e90b58c3f02f368ff9b768a5aa25f07fbef Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 00:31:40 +0100 Subject: [PATCH 024/117] fix: cleanup --- plugins/modules/host.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 7f77eb08f..d5c6a569f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -247,15 +247,12 @@ def __init__(self, module): self.desired["folder"] = "/" else: if self.params.get("folder"): - self.desired["folder"] = self._normalize_folder(self.params.get("folder")) + self.desired["folder"] = self._normalize_folder( + self.params.get("folder") + ) else: self.desired["folder"] = "/" - if not self.current.get("folder") or ( - self.params.get("folder") and tmp_folder != self.current.get("folder") - ): - self.desired["folder"] = tmp_folder - self._changed_items = self._detect_changes() self._verify_compatibility() From 8e3f13660bb5509d0fd5a70b4200dad23eb9661a Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 00:46:09 +0100 Subject: [PATCH 025/117] check: --- plugins/modules/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index d5c6a569f..d96b76fdc 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -240,7 +240,7 @@ def __init__(self, module): if self.current.get("folder"): if self.params.get("folder"): tmp_folder = self._normalize_folder(self.params.get("folder")) - if tmp_folder != self.current.get("folder"): + if tmp_folder != self._normalize_folder(self.current.get("folder")): self.desired["folder"] = tmp_folder else: if self.current.get("folder") != "/": @@ -249,7 +249,7 @@ def __init__(self, module): if self.params.get("folder"): self.desired["folder"] = self._normalize_folder( self.params.get("folder") - ) + ) else: self.desired["folder"] = "/" From f7267befe4c8c0578e33ef2a759cfc9115d8c8d0 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 00:58:56 +0100 Subject: [PATCH 026/117] test: workaround --- plugins/modules/host.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index d96b76fdc..4376a89cd 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -204,7 +204,10 @@ class HostHTTPCodes: create = {200: (True, False, "Host created")} edit = {200: (True, False, "Host modified")} - move = {200: (True, False, "Host moved")} + move = { + 200: (True, False, "Host moved"), + 400: (False, False, "The host is already part of the specified target folder"), + } delete = {204: (True, False, "Host deleted")} From 2da16650e3fb3ec42f9d928252b5c3ae6a559c6f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 01:06:16 +0100 Subject: [PATCH 027/117] cleanup: --- plugins/modules/host.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 4376a89cd..236392acf 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -412,7 +412,6 @@ def _get_current(self): content = json.loads(result.content) extensions = content["extensions"] - self.current["folder"] = extensions.pop("folder", "/") for key, value in extensions.items(): if key == "attributes": value.pop("meta_data") From 6b9d11a2ce92057cb57d662bb915e462e1cb12b7 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 01:22:42 +0100 Subject: [PATCH 028/117] refactor: remove workaround --- plugins/modules/host.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 236392acf..906722bfa 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -204,10 +204,7 @@ class HostHTTPCodes: create = {200: (True, False, "Host created")} edit = {200: (True, False, "Host modified")} - move = { - 200: (True, False, "Host moved"), - 400: (False, False, "The host is already part of the specified target folder"), - } + move = {200: (True, False, "Host moved")} delete = {204: (True, False, "Host deleted")} @@ -246,7 +243,7 @@ def __init__(self, module): if tmp_folder != self._normalize_folder(self.current.get("folder")): self.desired["folder"] = tmp_folder else: - if self.current.get("folder") != "/": + if self._normalize_folder(self.current.get("folder")) != "/": self.desired["folder"] = "/" else: if self.params.get("folder"): From 4637a397faf0860156b2d05eb875327bcabf2383 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 01:33:22 +0100 Subject: [PATCH 029/117] cleanup: --- plugins/modules/host.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 906722bfa..17d6cf314 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -240,10 +240,10 @@ def __init__(self, module): if self.current.get("folder"): if self.params.get("folder"): tmp_folder = self._normalize_folder(self.params.get("folder")) - if tmp_folder != self._normalize_folder(self.current.get("folder")): + if tmp_folder != self.current.get("folder"): self.desired["folder"] = tmp_folder else: - if self._normalize_folder(self.current.get("folder")) != "/": + if self.current.get("folder") != "/": self.desired["folder"] = "/" else: if self.params.get("folder"): @@ -415,6 +415,7 @@ def _get_current(self): if "network_scan_results" in value: value.pop("network_scan_results") self.current[key] = value + self.current["folder"] = self._normalize_folder(self.current.get("folder", "/")) self.etag = result.etag From eb13ab1ac768619a44dd1140dc437a6468c0bb5f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 02:16:15 +0100 Subject: [PATCH 030/117] cleanup: --- plugins/modules/host.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 17d6cf314..87068ddc5 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -334,7 +334,7 @@ def _detect_changes(self): if desired_attributes.get( "attributes" ) and current_attributes != desired_attributes.get("attributes"): - changes.append("attributes") + changes.append("attributes: %s" % json.dumps(desired_attributes.get("attributes"))) if ( desired_attributes.get("folder") @@ -415,7 +415,9 @@ def _get_current(self): if "network_scan_results" in value: value.pop("network_scan_results") self.current[key] = value - self.current["folder"] = self._normalize_folder(self.current.get("folder", "/")) + self.current["folder"] = self._normalize_folder( + self.current.get("folder", "/") + ) self.etag = result.etag From fb6f4421b9fe7ab5b15926977d0fe40182a9e13e Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 02:18:53 +0100 Subject: [PATCH 031/117] add: ~ as a possible default folder --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 87068ddc5..e71833074 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -290,7 +290,7 @@ def _verify_compatibility(self): self.module.warn(msg) def _normalize_folder(self, folder): - if folder and folder in ["", " ", "/", "//"]: + if folder and folder in ["", " ", "/", "//", "~"]: return "/" if not folder.startswith("/"): From 4cd22d3b947c2c0d87e921110a63f66f4f93a197 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 02:32:38 +0100 Subject: [PATCH 032/117] add: effective_attributes --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e71833074..f8629851c 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -399,7 +399,7 @@ def _detect_changes(self): def _get_current(self): result = self._fetch( code_mapping=HostHTTPCodes.get, - endpoint=self._build_default_endpoint(), + endpoint=self._build_default_endpoint() + "?effective_attributes=true", method="GET", ) From 56689a0ace048e7ae297cde29fc0808de8aff33a Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 02:47:16 +0100 Subject: [PATCH 033/117] fix: style --- plugins/modules/host.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index f8629851c..e772be96a 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -334,7 +334,9 @@ def _detect_changes(self): if desired_attributes.get( "attributes" ) and current_attributes != desired_attributes.get("attributes"): - changes.append("attributes: %s" % json.dumps(desired_attributes.get("attributes"))) + changes.append( + "attributes: %s" % json.dumps(desired_attributes.get("attributes")) + ) if ( desired_attributes.get("folder") From 7079bf5e45a092520fbc84b15531d3c544c29152 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 04:16:54 +0100 Subject: [PATCH 034/117] refactor: --- plugins/modules/host.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e772be96a..905f41a4b 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -237,21 +237,16 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if self.current.get("folder"): - if self.params.get("folder"): - tmp_folder = self._normalize_folder(self.params.get("folder")) - if tmp_folder != self.current.get("folder"): - self.desired["folder"] = tmp_folder - else: - if self.current.get("folder") != "/": - self.desired["folder"] = "/" + if self.params.get("folder"): + tmp_folder = self._normalize_folder(self.params.get("folder")) else: - if self.params.get("folder"): - self.desired["folder"] = self._normalize_folder( - self.params.get("folder") - ) - else: - self.desired["folder"] = "/" + tmp_folder = self._normalize_folder("/") + + if current_host.state == "present": + if tmp_folder != self.current.get("folder"): + self.desired["folder"] = tmp_folder + else: + self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() From 6e467324875a875a9086d77fbb32c8ec4ea7cd8f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 04:22:59 +0100 Subject: [PATCH 035/117] fix: copy paste --- plugins/modules/host.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 905f41a4b..e4f4911db 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -219,6 +219,11 @@ def __init__(self, module): self.extended_functionality = self.params.get("extended_functionality", True) + if self.params.get("folder"): + tmp_folder = self._normalize_folder(self.params.get("folder")) + else: + tmp_folder = self._normalize_folder("/") + self.desired = {} self.desired["host_name"] = self.params.get("name") @@ -237,12 +242,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if self.params.get("folder"): - tmp_folder = self._normalize_folder(self.params.get("folder")) - else: - tmp_folder = self._normalize_folder("/") - - if current_host.state == "present": + if self.current.state == "present": if tmp_folder != self.current.get("folder"): self.desired["folder"] = tmp_folder else: From 7afe850ec77bc80eb6929b850e05914579465ff4 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 04:27:28 +0100 Subject: [PATCH 036/117] fix: copy paste --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e4f4911db..5ce72c35e 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -242,7 +242,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if self.current.state == "present": + if self.state == "present": if tmp_folder != self.current.get("folder"): self.desired["folder"] = tmp_folder else: From cce2eb36deaa1ad00cf6561d66c4748fb0533947 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 04:43:14 +0100 Subject: [PATCH 037/117] refactor: --- plugins/modules/host.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 5ce72c35e..fb0d0bfea 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -424,7 +424,9 @@ def _get_current(self): def _check_output(self, mode): return RESULT( http_code=0, - msg="Running in check mode. Would have done an %s" % mode, + msg="Running in check mode. Would have done an %s. Changed: %s" % ( + mode, ", ".join(self._changed_items) + ), content="", etag="", failed=False, @@ -442,9 +444,6 @@ def create(self): if data.get("remove_attributes"): data.pop("remove_attributes") - if data.get("folder"): - data["folder"] = "/" - if self.module.check_mode: return self._check_output("create") @@ -463,6 +462,12 @@ def edit(self): self.headers["if-Match"] = self.etag + if data.get("update_attributes") == {}: + data.pop("update_attributes") + + if data.get("remove_attributes") == []: + data.pop("remove_attributes") + if self.module.check_mode: return self._check_output("edit") @@ -481,15 +486,6 @@ def edit(self): msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) - if self.module.check_mode: - return self._check_output("edit") - - if data.get("update_attributes") == {}: - data.pop("update_attributes") - - if data.get("remove_attributes") == []: - data.pop("remove_attributes") - if data.get("update_attributes") and data.get("remove_attributes"): tmp = data.copy() tmp.pop("remove_attributes") From e4966e233606174e44bd9dd081834b1d102cf430 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 04:54:45 +0100 Subject: [PATCH 038/117] cleanup: --- plugins/modules/host.py | 43 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index fb0d0bfea..1c8c7f8b9 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -424,9 +424,8 @@ def _get_current(self): def _check_output(self, mode): return RESULT( http_code=0, - msg="Running in check mode. Would have done an %s. Changed: %s" % ( - mode, ", ".join(self._changed_items) - ), + msg="Running in check mode. Would have done an %s. Changed: %s" + % (mode, ", ".join(self._changed_items)), content="", etag="", failed=False, @@ -462,12 +461,6 @@ def edit(self): self.headers["if-Match"] = self.etag - if data.get("update_attributes") == {}: - data.pop("update_attributes") - - if data.get("remove_attributes") == []: - data.pop("remove_attributes") - if self.module.check_mode: return self._check_output("edit") @@ -486,32 +479,12 @@ def edit(self): msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) - if data.get("update_attributes") and data.get("remove_attributes"): - tmp = data.copy() - tmp.pop("remove_attributes") - self.module.fail_json(json.dumps(tmp)) - result = self._fetch( - code_mapping=HostHTTPCodes.edit, - endpoint=self._build_default_endpoint(), - data=tmp, - method="PUT", - ) - - tmp = data.copy() - tmp.pop("update_attributes") - result = self._fetch( - code_mapping=HostHTTPCodes.edit, - endpoint=self._build_default_endpoint(), - data=tmp, - method="PUT", - ) - else: - result = self._fetch( - code_mapping=HostHTTPCodes.edit, - endpoint=self._build_default_endpoint(), - data=data, - method="PUT", - ) + result = self._fetch( + code_mapping=HostHTTPCodes.edit, + endpoint=self._build_default_endpoint(), + data=data, + method="PUT", + ) return result._replace( msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) From 9f21b919327f38debc726f719a5948e48d703fff Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 05:09:40 +0100 Subject: [PATCH 039/117] add: extend edit msg --- plugins/modules/host.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 1c8c7f8b9..e8278a599 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -464,19 +464,20 @@ def edit(self): if self.module.check_mode: return self._check_output("edit") + result_move = {} if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") - result = self._fetch( + result_move = self._fetch( code_mapping=HostHTTPCodes.move, endpoint=self._build_move_endpoint(), data=tmp, method="POST", ) - result._replace( - msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") + result_move._replace( + msg=result_move.msg + ". Moved to: %s" % tmp.get("target_folder") ) result = self._fetch( @@ -487,7 +488,7 @@ def edit(self): ) return result._replace( - msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) + msg=result_move.get("msg", "") + result.msg + ". Changed: %s" % ", ".join(self._changed_items) ) def delete(self): From ab07411b6df0dba11909db25d6c3e565162c3295 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 05:22:16 +0100 Subject: [PATCH 040/117] fix: --- plugins/modules/host.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e8278a599..5022d6907 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -488,7 +488,9 @@ def edit(self): ) return result._replace( - msg=result_move.get("msg", "") + result.msg + ". Changed: %s" % ", ".join(self._changed_items) + msg=(result_move.msg if result_move != {} else "") + + result.msg + + ". Changed: %s" % ", ".join(self._changed_items) ) def delete(self): From 2bea0f44a444f59ac838f9444853300f4edf124d Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 05:36:45 +0100 Subject: [PATCH 041/117] fix: --- plugins/modules/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 5022d6907..1a73badd3 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -476,7 +476,7 @@ def edit(self): method="POST", ) - result_move._replace( + result_move = result_move._replace( msg=result_move.msg + ". Moved to: %s" % tmp.get("target_folder") ) @@ -488,7 +488,7 @@ def edit(self): ) return result._replace( - msg=(result_move.msg if result_move != {} else "") + msg=((result_move.msg + ". ") if result_move != {} else "") + result.msg + ". Changed: %s" % ", ".join(self._changed_items) ) From 3d6fbcab3303db2601ee31efd4ba11948e3c5447 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 05:51:26 +0100 Subject: [PATCH 042/117] test: --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 1a73badd3..df2797ca0 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -477,7 +477,7 @@ def edit(self): ) result_move = result_move._replace( - msg=result_move.msg + ". Moved to: %s" % tmp.get("target_folder") + msg=result_move.msg + ". Moved from % to: %s" % (self.current.get("folder"), tmp.get("target_folder")) ) result = self._fetch( From 22cc4437099b551a06f63185d76fed3fec7cb58f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 05:59:57 +0100 Subject: [PATCH 043/117] fix: test --- plugins/modules/host.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index df2797ca0..3fb89d9c6 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -477,7 +477,8 @@ def edit(self): ) result_move = result_move._replace( - msg=result_move.msg + ". Moved from % to: %s" % (self.current.get("folder"), tmp.get("target_folder")) + msg=result_move.msg + + ". Moved from %s to: %s" % (self.current.get("folder"), tmp.get("target_folder")) ) result = self._fetch( From c198850a65cdd69609c73d4aa06df0d61739427e Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:14:52 +0100 Subject: [PATCH 044/117] fix: refactor logic of folder field --- plugins/modules/host.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 3fb89d9c6..04a1e663f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -219,10 +219,8 @@ def __init__(self, module): self.extended_functionality = self.params.get("extended_functionality", True) - if self.params.get("folder"): - tmp_folder = self._normalize_folder(self.params.get("folder")) - else: - tmp_folder = self._normalize_folder("/") + if self.params["folder"]: + self.params["folder"] = self._normalize_folder(self.params.get("folder")) self.desired = {} @@ -243,10 +241,8 @@ def __init__(self, module): self._get_current() if self.state == "present": - if tmp_folder != self.current.get("folder"): + if self.params["folder"] and self.current["folder"] != self.params["folder"] self.desired["folder"] = tmp_folder - else: - self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() @@ -443,6 +439,9 @@ def create(self): if data.get("remove_attributes"): data.pop("remove_attributes") + if not data["folder"]: + data["folder"] = self._normalize_folder("/") + if self.module.check_mode: return self._check_output("create") From 4fb4876bcff56e5e2e437f1b66896e6cc83c8d7b Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:16:37 +0100 Subject: [PATCH 045/117] fix: ups : --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 04a1e663f..4ea5a771f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -241,7 +241,7 @@ def __init__(self, module): self._get_current() if self.state == "present": - if self.params["folder"] and self.current["folder"] != self.params["folder"] + if self.params["folder"] and self.current["folder"] != self.params["folder"]: self.desired["folder"] = tmp_folder self._changed_items = self._detect_changes() From aee96fa9dda93bf89324fb45dbd1f6bfb9c79506 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:23:28 +0100 Subject: [PATCH 046/117] fix: --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 4ea5a771f..5d52ce250 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -439,7 +439,7 @@ def create(self): if data.get("remove_attributes"): data.pop("remove_attributes") - if not data["folder"]: + if not data.get("folder"): data["folder"] = self._normalize_folder("/") if self.module.check_mode: From bc9ebdd40bfda5cd04bf4dc9e6d57b9d7eac1917 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:28:55 +0100 Subject: [PATCH 047/117] fix: cleanup --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 5d52ce250..e98c69e71 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -242,7 +242,7 @@ def __init__(self, module): if self.state == "present": if self.params["folder"] and self.current["folder"] != self.params["folder"]: - self.desired["folder"] = tmp_folder + self.desired["folder"] = self.params["folder"] self._changed_items = self._detect_changes() From 3a26e222084366135d5d908290a1d0825b09d1a5 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:38:40 +0100 Subject: [PATCH 048/117] cleanup: --- plugins/modules/host.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e98c69e71..f0755f348 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -219,7 +219,7 @@ def __init__(self, module): self.extended_functionality = self.params.get("extended_functionality", True) - if self.params["folder"]: + if self.params.get("folder"): self.params["folder"] = self._normalize_folder(self.params.get("folder")) self.desired = {} @@ -241,7 +241,7 @@ def __init__(self, module): self._get_current() if self.state == "present": - if self.params["folder"] and self.current["folder"] != self.params["folder"]: + if self.params.get("folder") and self.current["folder"] != self.params["folder"]: self.desired["folder"] = self.params["folder"] self._changed_items = self._detect_changes() @@ -281,7 +281,7 @@ def _verify_compatibility(self): self.module.warn(msg) def _normalize_folder(self, folder): - if folder and folder in ["", " ", "/", "//", "~"]: + if folder in ["", " ", "/", "//", "~"]: return "/" if not folder.startswith("/"): @@ -476,8 +476,7 @@ def edit(self): ) result_move = result_move._replace( - msg=result_move.msg - + ". Moved from %s to: %s" % (self.current.get("folder"), tmp.get("target_folder")) + msg=result_move.msg + ". Moved from to: %s" % tmp.get("target_folder") ) result = self._fetch( From cf73d22d13f86622889f6ad816398e2a43b9c28e Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 14:41:27 +0100 Subject: [PATCH 049/117] fix: style --- plugins/modules/host.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index f0755f348..249cebf7c 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -241,7 +241,10 @@ def __init__(self, module): self._get_current() if self.state == "present": - if self.params.get("folder") and self.current["folder"] != self.params["folder"]: + if ( + self.params.get("folder") + and self.current["folder"] != self.params["folder"] + ): self.desired["folder"] = self.params["folder"] self._changed_items = self._detect_changes() From 450877cdc6c48898451264ee148ba1f9d9287bd1 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 21:55:05 +0100 Subject: [PATCH 050/117] add: author --- plugins/modules/host.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 249cebf7c..2834fe4b9 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -70,6 +70,7 @@ - Robin Gierse (@robin-checkmk) - Lars Getwan (@lgetwan) - Oliver Gaida (@ogaida) + - Michael Sekania (@msekania) """ EXAMPLES = r""" From 4653caa9d3dafe57d28c7cde6739a7a84c0db9e1 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 22:17:34 +0100 Subject: [PATCH 051/117] fix: copy pase error --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 2834fe4b9..e13815bda 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -551,7 +551,7 @@ def run_module(): elif current_host.needs_update(): result = current_host.edit() elif current_host.state == "absent": - result = result._replace(msg="Folder already absent.") + result = result._replace(msg="Host already absent.") if desired_state in ("present"): result = current_host.create() From f15a4aa0b17b308f79ba61ba2e543b43adece87f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Sun, 18 Feb 2024 22:43:13 +0100 Subject: [PATCH 052/117] refactor: --- plugins/modules/host.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e13815bda..697678d79 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -310,6 +310,7 @@ def _build_move_endpoint(self): def _detect_changes(self): current_attributes = self.current.get("attributes", {}) + current_folder = self.current.get("folder") desired_attributes = self.desired.copy() changes = [] @@ -335,8 +336,8 @@ def _detect_changes(self): if ( desired_attributes.get("folder") - and self.current.get("folder") - and self.current.get("folder") != desired_attributes.get("folder") + and current_folder + and current_folder != desired_attributes.get("folder") ): changes.append("folder") From f03bc2d112704f0d291f379d06ad56a494eb95a0 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 20 Feb 2024 16:41:17 +0100 Subject: [PATCH 053/117] init: extend host module to handle clusters and add rename functionality --- plugins/modules/host.py | 350 +++++++++++++++++++++++++++++++++++----- 1 file changed, 307 insertions(+), 43 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 697678d79..b3e8a3622 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -65,6 +65,31 @@ description: Allow extended functionality instead of the expected REST API behavior. type: bool default: true + new_name: + description: The new name of the managed host. + required: false + type: str + nodes: + description: + - Nodes, members of the cluster-container host provided in name. + required: false + type: list + elements: str + add_nodes: + description: + - List of nodes to be added as members of the cluster-container host provided in name. + Works only if the existing host was already a cluster host, or entirely new is created. + B(Mutualy exclusive with nodes.) + required: false + type: list + elements: str + nodes: + description: + - List of nodes to be removes from the cluster-container host provided in name. + B(Mutualy exclusive with nodes.) + required: false + type: list + elements: str author: - Robin Gierse (@robin-checkmk) @@ -112,6 +137,36 @@ folder: "/" state: "present" +# Create a cluster host. +- name: "Create a cluster host." + checkmk.general.cluster: + server_url: "http://my_server/" + site: "my_site" + automation_user: "my_user" + automation_secret: "my_secret" + name: "my_cluster_host" + folder: "/" + nodes: ["cluster_node_1", "cluster_node_2", "cluster_node_3"] + state: "present" + +# Create a cluster host with IP. +- name: "Create a cluster host with IP address." + checkmk.general.cluster: + server_url: "http://my_server/" + site: "my_site" + automation_user: "my_user" + automation_secret: "my_secret" + name: "my_cluster_host" + nodes: + - "cluster_node_1" + - "cluster_node_2" + - "cluster_node_3" + attributes: + alias: "My Cluster Host" + ipaddress: "127.0.0.1" + folder: "/" + state: "present" + # Create a host with update_attributes. - name: "Create a host which is monitored on a distinct site." checkmk.general.host: @@ -204,14 +259,22 @@ class HostHTTPCodes: } create = {200: (True, False, "Host created")} + create_cluster = {200: (True, False, "Cluster host created")} edit = {200: (True, False, "Host modified")} move = {200: (True, False, "Host moved")} + rename = {200: (True, False, "Host renamed")} + modify_cluster = { + 200: (True, False, "Cluster host nodes modified"), + } delete = {204: (True, False, "Host deleted")} class HostEndpoints: default = "/objects/host_config" create = "/domain-types/host_config/collections/all" + rename = "/objects/host_config/%s/actions/rename/invoke" + create_cluster = "/domain-types/host_config/collections/clusters" + modify_cluster = "/objects/host_config/%s/properties/nodes" class HostAPI(CheckmkAPI): @@ -227,6 +290,18 @@ def __init__(self, module): self.desired["host_name"] = self.params.get("name") + if self.params.get("new_name"): + self.desired["new_name"] = self.params.get("new_name") + + if self.params.get("nodes"): + self.desired["nodes"] = self.params.get("nodes") + + if self.params.get("add_nodes"): + self.desired["add_nodes"] = self.params.get("add_nodes") + + if self.params.get("remove_nodes"): + self.desired["remove_nodes"] = self.params.get("remove_nodes") + for key in HOST: if self.params.get(key): self.desired[key] = self.params.get(key) @@ -308,11 +383,78 @@ def _build_move_endpoint(self): self.desired["host_name"], ) - def _detect_changes(self): - current_attributes = self.current.get("attributes", {}) + def _build_rename_endpoint(self): + return HostEndpoints.rename % self.desired["host_name"] + + def _build_modify_cluster_endpoint(self): + return HostEndpoints.modify_cluster % self.desired["host_name"] + + def _detect_changes_folder(self): current_folder = self.current.get("folder") + desired_folder = self.desired.get("folder") + + if ( + desired_folder + and current_folder + and current_folder != desired_folder + ): + self.changes.append("folder") + else + self.desired.pop("folder") + + + def _detect_changes_rename(self): + current_name = self.desired.get("name") + desired_name = self.desired.get("new_name") + + if ( + desired_name + and current_name != desired_name + ): + self.changes.append("rename") + else: + self.desired.pop("new_name") + + + def _detect_changes_nodes(self): + current_nodes = self.current.get("cluster_nodes", []) + + if ( + self.desired.get("nodes") + or self.desired.get("add_nodes") + or self.desired.get("remove_nodes") + ): + desired_nodes = self.desired.get("nodes", []) + + desired_nodes = desired_nodes + self.desired.get("add_nodes", []) + + desired_nodes = [el for el in desired_nodes if el not in self.desired.get("remove_nodes", [])] + + if ( + len([el for el in current_nodes if el not in desired_nodes]) > 0 + or len([el for el in desired_nodes if el not in current_nodes]) > 0 + ): + self.changes.append("nodes") + else: + self.desired.pop("nodes") + self.desired.pop("add_nodes") + self.desired.pop("remove_nodes") + + def _detect_changes_attributes(self): + current_attributes = self.current.get("attributes", {}) desired_attributes = self.desired.copy() - changes = [] + ATTRIBUTE_FILEDS = [ + "attributes", + "update_attributes", + "remove_attributes", + ] + + if desired_attributes.get( + "attributes" + ) and current_attributes != desired_attributes.get("attributes"): + changes.append( + "attributes: %s" % json.dumps(desired_attributes.get("attributes")) + ) if desired_attributes.get("update_attributes"): merged_attributes = dict_merge( @@ -327,20 +469,6 @@ def _detect_changes(self): changes.append("update attributes") desired_attributes["update_attributes"] = merged_attributes - if desired_attributes.get( - "attributes" - ) and current_attributes != desired_attributes.get("attributes"): - changes.append( - "attributes: %s" % json.dumps(desired_attributes.get("attributes")) - ) - - if ( - desired_attributes.get("folder") - and current_folder - and current_folder != desired_attributes.get("folder") - ): - changes.append("folder") - if desired_attributes.get("remove_attributes"): tmp_remove_attributes = desired_attributes.get("remove_attributes") @@ -388,11 +516,29 @@ def _detect_changes(self): ) if self.extended_functionality: - self.desired = desired_attributes.copy() + for key in ATTRIBUTE_FILEDS: + if desired_attributes.get(key): + self.desired[key] = desired_attributes.get(key) + else: + self.desired.pop(key) # self.module.fail_json(json.dumps(desired_attributes)) - return changes + def _detect_changes(self): + self.changes = [] + self.desired = {} + + loc_functions = [ + self._detect_changes_folder, + self._detect_changes_attributes, + self._detect_changes_nodes, + self._detect_changes_rename, + ] + + for fun in loc_functions: + fun() + + return self.changes def _get_current(self): result = self._fetch( @@ -450,40 +596,116 @@ def create(self): if self.module.check_mode: return self._check_output("create") - result = self._fetch( - code_mapping=HostHTTPCodes.create, - endpoint=HostEndpoints.create, - data=data, - method="POST", - ) + if not data.get("nodes"): + result = self._fetch( + code_mapping=HostHTTPCodes.create, + endpoint=HostEndpoints.create, + data=data, + method="POST", + ) + else: + result = self._fetch( + code_mapping=HostHTTPCodes.create_cluster, + endpoint=HostEndpoints.create_cluster, + data=data, + method="POST", + ) return result - def edit(self): - data = self.desired.copy() - data.pop("host_name") - - self.headers["if-Match"] = self.etag - - if self.module.check_mode: - return self._check_output("edit") + def _edit_folder(self): + result = RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) - result_move = {} - if data.get("folder"): + if self.desired.get("folder"): tmp = {} - tmp["target_folder"] = data.pop("folder") + tmp["target_folder"] = self.desired.get("folder") - result_move = self._fetch( + result = self._fetch( code_mapping=HostHTTPCodes.move, endpoint=self._build_move_endpoint(), data=tmp, method="POST", ) - result_move = result_move._replace( - msg=result_move.msg + ". Moved from to: %s" % tmp.get("target_folder") + result = result._replace( + msg=result.msg + ". Moved from to: %s" % tmp.get("target_folder") + ) + + return result + + def _edit_hostname(self): + result = RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) + + if self.desired.get("folder"): + tmp = {} + tmp["new_name"] = self.desired.get("new_name") + + result = self._fetch( + code_mapping=HostHTTPCodes.rename, + endpoint=self._build_rename_endpoint(), + data=tmp, + method="PUT", + ) + + result = result._replace( + msg=result.msg + ". renamed to: %s" % tmp.get("new_name") ) + return result + + def _edit_nodes(self): + result = RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) + + if self.desired.get("nodes"): + tmp = {} + tmp["nodes"] = self.desired.get("nodes") + + result = self._fetch( + code_mapping=HostHTTPCodes.modify_cluster, + endpoint=self._build_modify_cluster_endpoint(), + data=tmp, + method="PUT", + ) + + result = result._replace( + msg=result.msg + ". Nodes modified to: %s" % tmp.get("nodes") + ) + + return result + + def _edit_attributes(self): + data = self.desired.copy() + data.pop("host_name") + CLEAN_FIELDS = [ + "folder", + "nodes", + "new_name", + ] + + for key in CLEAN_FIELDS: + data.pop(key) + result = self._fetch( code_mapping=HostHTTPCodes.edit, endpoint=self._build_default_endpoint(), @@ -492,11 +714,42 @@ def edit(self): ) return result._replace( - msg=((result_move.msg + ". ") if result_move != {} else "") - + result.msg - + ". Changed: %s" % ", ".join(self._changed_items) + msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) ) + def edit(self): + self.desired.pop("host_name") + self.headers["if-Match"] = self.etag + + if self.module.check_mode: + return self._check_output("edit") + + result = RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) + + loc_functions = [ + self._edit_attributes, + self._edit_folder, + self._edit_hostname, + self._edit_nodes, + ] + + for fun in loc_functions: + result_loc = fun() + + result = result._replace( + msg=result.msg + (". " if result_loc.msg != "" else "") + result_loc.msg + change =result.change or result_loc.change + ) + + return result + def delete(self): if self.module.check_mode: return self._check_output("delete") @@ -528,9 +781,20 @@ def run_module(): folder=dict(type="str", required=False), state=dict(type="str", default="present", choices=["present", "absent"]), extended_functionality=dict(type="bool", required=False, default=True), + new_name=dict(type="str", required=False), + nodes=dict(type="list", required=False, elements="str"), + add_nodes=dict(type="list", required=False, elements="str"), + remove_nodes=dict(type="list", required=False, elements="str"), ) - module = AnsibleModule(argument_spec=module_args, supports_check_mode=True) + module = AnsibleModule( + argument_spec=module_args, + mutually_exclusive=[ + ("nodes", "add_nodes"), + ("nodes", "remove_nodes"), + ], + supports_check_mode=True + ) # Create an API object that contains the current and desired state current_host = HostAPI(module) From c6d3bce214da4ad3ac447e5bbec4665c776a221d Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 20 Feb 2024 16:43:11 +0100 Subject: [PATCH 054/117] fix: syntax --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index b3e8a3622..6428999d7 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -399,7 +399,7 @@ def _detect_changes_folder(self): and current_folder != desired_folder ): self.changes.append("folder") - else + else: self.desired.pop("folder") From c7e7df65a3840e806f0f4daabf1a83ba417e4a25 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 20 Feb 2024 16:45:52 +0100 Subject: [PATCH 055/117] fix: syntax --- plugins/modules/host.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 6428999d7..4d8d821d4 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -402,7 +402,6 @@ def _detect_changes_folder(self): else: self.desired.pop("folder") - def _detect_changes_rename(self): current_name = self.desired.get("name") desired_name = self.desired.get("new_name") @@ -415,7 +414,6 @@ def _detect_changes_rename(self): else: self.desired.pop("new_name") - def _detect_changes_nodes(self): current_nodes = self.current.get("cluster_nodes", []) @@ -744,8 +742,8 @@ def edit(self): result_loc = fun() result = result._replace( - msg=result.msg + (". " if result_loc.msg != "" else "") + result_loc.msg - change =result.change or result_loc.change + msg=result.msg + (". " if result_loc.msg != "" else "") + result_loc.msg, + change=result.change | result_loc.change, ) return result From 0c4e6b235852f73e928d5a3e16497957fb529dd0 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 20 Feb 2024 16:50:42 +0100 Subject: [PATCH 056/117] fix: syntax, style, errors --- plugins/modules/host.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 4d8d821d4..670307234 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -83,7 +83,7 @@ required: false type: list elements: str - nodes: + remove_nodes: description: - List of nodes to be removes from the cluster-container host provided in name. B(Mutualy exclusive with nodes.) @@ -393,11 +393,7 @@ def _detect_changes_folder(self): current_folder = self.current.get("folder") desired_folder = self.desired.get("folder") - if ( - desired_folder - and current_folder - and current_folder != desired_folder - ): + if desired_folder and current_folder and current_folder != desired_folder: self.changes.append("folder") else: self.desired.pop("folder") @@ -406,10 +402,7 @@ def _detect_changes_rename(self): current_name = self.desired.get("name") desired_name = self.desired.get("new_name") - if ( - desired_name - and current_name != desired_name - ): + if desired_name and current_name != desired_name: self.changes.append("rename") else: self.desired.pop("new_name") @@ -426,7 +419,11 @@ def _detect_changes_nodes(self): desired_nodes = desired_nodes + self.desired.get("add_nodes", []) - desired_nodes = [el for el in desired_nodes if el not in self.desired.get("remove_nodes", [])] + desired_nodes = [ + el + for el in desired_nodes + if el not in self.desired.get("remove_nodes", []) + ] if ( len([el for el in current_nodes if el not in desired_nodes]) > 0 @@ -450,7 +447,7 @@ def _detect_changes_attributes(self): if desired_attributes.get( "attributes" ) and current_attributes != desired_attributes.get("attributes"): - changes.append( + self.changes.append( "attributes: %s" % json.dumps(desired_attributes.get("attributes")) ) @@ -462,9 +459,9 @@ def _detect_changes_attributes(self): if merged_attributes != current_attributes: try: (c_m, m_c) = recursive_diff(current_attributes, merged_attributes) - changes.append("update attributes: %s" % json.dumps(m_c)) + self.changes.append("update attributes: %s" % json.dumps(m_c)) except Exception as e: - changes.append("update attributes") + self.changes.append("update attributes") desired_attributes["update_attributes"] = merged_attributes if desired_attributes.get("remove_attributes"): @@ -475,7 +472,7 @@ def _detect_changes_attributes(self): a for a in tmp_remove_attributes if current_attributes.get(a) ] if len(removes_which) > 0: - changes.append("remove attributes: %s" % " ".join(removes_which)) + self.changes.append("remove attributes: %s" % " ".join(removes_which)) elif isinstance(tmp_remove_attributes, dict): if not self.extended_functionality: self.module.fail_json( @@ -504,7 +501,7 @@ def _detect_changes_attributes(self): desired_attributes.pop("remove_attributes") if tmp_remove != {}: - changes.append("remove attributes: %s" % json.dumps(tmp_remove)) + self.changes.append("remove attributes: %s" % json.dumps(tmp_remove)) if tmp_rest != {}: desired_attributes["update_attributes"] = tmp_rest else: @@ -742,7 +739,9 @@ def edit(self): result_loc = fun() result = result._replace( - msg=result.msg + (". " if result_loc.msg != "" else "") + result_loc.msg, + msg=result.msg + + (". " if result_loc.msg != "" else "") + + result_loc.msg, change=result.change | result_loc.change, ) @@ -791,7 +790,7 @@ def run_module(): ("nodes", "add_nodes"), ("nodes", "remove_nodes"), ], - supports_check_mode=True + supports_check_mode=True, ) # Create an API object that contains the current and desired state From 8c464c610155525ba2f8ed2bd4702c9d848bc5c3 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 20 Feb 2024 16:52:30 +0100 Subject: [PATCH 057/117] fix: style --- plugins/modules/host.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 670307234..bb3230687 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -472,7 +472,9 @@ def _detect_changes_attributes(self): a for a in tmp_remove_attributes if current_attributes.get(a) ] if len(removes_which) > 0: - self.changes.append("remove attributes: %s" % " ".join(removes_which)) + self.changes.append( + "remove attributes: %s" % " ".join(removes_which) + ) elif isinstance(tmp_remove_attributes, dict): if not self.extended_functionality: self.module.fail_json( @@ -501,7 +503,9 @@ def _detect_changes_attributes(self): desired_attributes.pop("remove_attributes") if tmp_remove != {}: - self.changes.append("remove attributes: %s" % json.dumps(tmp_remove)) + self.changes.append( + "remove attributes: %s" % json.dumps(tmp_remove) + ) if tmp_rest != {}: desired_attributes["update_attributes"] = tmp_rest else: From baef4f91834a6f902b75c37da3f527e630463756 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 12:03:44 +0100 Subject: [PATCH 058/117] fix: errors --- plugins/modules/host.py | 98 +++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index bb3230687..c00f2b7fd 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -65,10 +65,10 @@ description: Allow extended functionality instead of the expected REST API behavior. type: bool default: true - new_name: - description: The new name of the managed host. - required: false - type: str + # new_name: + # description: The new name of the managed host. + # required: false + # type: str nodes: description: - Nodes, members of the cluster-container host provided in name. @@ -261,6 +261,10 @@ class HostHTTPCodes: create = {200: (True, False, "Host created")} create_cluster = {200: (True, False, "Cluster host created")} edit = {200: (True, False, "Host modified")} + edit_cluster = { + 200: (True, False, "Host modified"), + 412: (True, False, "eTag changed, because cluster host nodes were modified"), + } move = {200: (True, False, "Host moved")} rename = {200: (True, False, "Host renamed")} modify_cluster = { @@ -392,23 +396,33 @@ def _build_modify_cluster_endpoint(self): def _detect_changes_folder(self): current_folder = self.current.get("folder") desired_folder = self.desired.get("folder") + changes = [] if desired_folder and current_folder and current_folder != desired_folder: - self.changes.append("folder") + changes.append("folder") else: - self.desired.pop("folder") + self.desired.pop("folder", "") + + return changes def _detect_changes_rename(self): current_name = self.desired.get("name") desired_name = self.desired.get("new_name") + changes = [] if desired_name and current_name != desired_name: - self.changes.append("rename") + changes.append("rename") else: - self.desired.pop("new_name") + self.desired.pop("new_name", "") + + return changes def _detect_changes_nodes(self): - current_nodes = self.current.get("cluster_nodes", []) + changes = [] + + current_nodes = [] + if self.current.get("cluster_nodes"): + current_nodes = self.current.get("cluster_nodes") if ( self.desired.get("nodes") @@ -429,26 +443,30 @@ def _detect_changes_nodes(self): len([el for el in current_nodes if el not in desired_nodes]) > 0 or len([el for el in desired_nodes if el not in current_nodes]) > 0 ): - self.changes.append("nodes") + changes.append("nodes") else: - self.desired.pop("nodes") - self.desired.pop("add_nodes") - self.desired.pop("remove_nodes") + self.desired.pop("nodes", []) + self.desired.pop("add_nodes", []) + self.desired.pop("remove_nodes", []) + + return changes def _detect_changes_attributes(self): - current_attributes = self.current.get("attributes", {}) - desired_attributes = self.desired.copy() ATTRIBUTE_FILEDS = [ "attributes", "update_attributes", "remove_attributes", ] + current_attributes = self.current.get("attributes", {}) + desired_attributes = self.desired.copy() + changes = [] + if desired_attributes.get( "attributes" ) and current_attributes != desired_attributes.get("attributes"): - self.changes.append( - "attributes: %s" % json.dumps(desired_attributes.get("attributes")) + changes.append( + "attributes: %s %s" % (json.dumps(current_attributes), json.dumps(desired_attributes.get("attributes"))) ) if desired_attributes.get("update_attributes"): @@ -459,9 +477,9 @@ def _detect_changes_attributes(self): if merged_attributes != current_attributes: try: (c_m, m_c) = recursive_diff(current_attributes, merged_attributes) - self.changes.append("update attributes: %s" % json.dumps(m_c)) + changes.append("update attributes: %s" % json.dumps(m_c)) except Exception as e: - self.changes.append("update attributes") + changes.append("update attributes") desired_attributes["update_attributes"] = merged_attributes if desired_attributes.get("remove_attributes"): @@ -472,7 +490,7 @@ def _detect_changes_attributes(self): a for a in tmp_remove_attributes if current_attributes.get(a) ] if len(removes_which) > 0: - self.changes.append( + changes.append( "remove attributes: %s" % " ".join(removes_which) ) elif isinstance(tmp_remove_attributes, dict): @@ -501,9 +519,9 @@ def _detect_changes_attributes(self): exception=e, ) - desired_attributes.pop("remove_attributes") + desired_attributes.pop("remove_attributes", {}) if tmp_remove != {}: - self.changes.append( + changes.append( "remove attributes: %s" % json.dumps(tmp_remove) ) if tmp_rest != {}: @@ -519,13 +537,12 @@ def _detect_changes_attributes(self): if desired_attributes.get(key): self.desired[key] = desired_attributes.get(key) else: - self.desired.pop(key) + self.desired.pop(key, "") - # self.module.fail_json(json.dumps(desired_attributes)) + return changes def _detect_changes(self): - self.changes = [] - self.desired = {} + changes = [] loc_functions = [ self._detect_changes_folder, @@ -535,9 +552,9 @@ def _detect_changes(self): ] for fun in loc_functions: - fun() + changes += fun() - return self.changes + return changes def _get_current(self): result = self._fetch( @@ -564,6 +581,10 @@ def _get_current(self): self.etag = result.etag + if self.current.get("cluster_nodes"): + self.is_cluster = True + else: + self.is_cluster = False else: self.state = "absent" @@ -649,10 +670,12 @@ def _edit_hostname(self): changed=False, ) - if self.desired.get("folder"): + if self.desired.get("new_name"): tmp = {} tmp["new_name"] = self.desired.get("new_name") + # self.module.fail_json(", ".join(self._changed_items)) + result = self._fetch( code_mapping=HostHTTPCodes.rename, endpoint=self._build_rename_endpoint(), @@ -695,18 +718,19 @@ def _edit_nodes(self): def _edit_attributes(self): data = self.desired.copy() - data.pop("host_name") + # data.pop("host_name") CLEAN_FIELDS = [ + "host_name", "folder", "nodes", "new_name", ] for key in CLEAN_FIELDS: - data.pop(key) + data.pop(key, "") result = self._fetch( - code_mapping=HostHTTPCodes.edit, + code_mapping=(HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit), endpoint=self._build_default_endpoint(), data=data, method="PUT", @@ -717,7 +741,6 @@ def _edit_attributes(self): ) def edit(self): - self.desired.pop("host_name") self.headers["if-Match"] = self.etag if self.module.check_mode: @@ -733,10 +756,11 @@ def edit(self): ) loc_functions = [ + # _edit_nodes should be always before _edit_attributes + self._edit_nodes, self._edit_attributes, self._edit_folder, - self._edit_hostname, - self._edit_nodes, + # self._edit_hostname, ] for fun in loc_functions: @@ -746,7 +770,7 @@ def edit(self): msg=result.msg + (". " if result_loc.msg != "" else "") + result_loc.msg, - change=result.change | result_loc.change, + changed=result.changed | result_loc.changed, ) return result @@ -782,7 +806,7 @@ def run_module(): folder=dict(type="str", required=False), state=dict(type="str", default="present", choices=["present", "absent"]), extended_functionality=dict(type="bool", required=False, default=True), - new_name=dict(type="str", required=False), + # new_name=dict(type="str", required=False), nodes=dict(type="list", required=False, elements="str"), add_nodes=dict(type="list", required=False, elements="str"), remove_nodes=dict(type="list", required=False, elements="str"), From bb6829937c76cf109fb194f3bd648019776c4e31 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 12:07:38 +0100 Subject: [PATCH 059/117] fix: style --- plugins/modules/host.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index c00f2b7fd..35063369a 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -466,7 +466,11 @@ def _detect_changes_attributes(self): "attributes" ) and current_attributes != desired_attributes.get("attributes"): changes.append( - "attributes: %s %s" % (json.dumps(current_attributes), json.dumps(desired_attributes.get("attributes"))) + "attributes: %s %s" + % ( + json.dumps(current_attributes), + json.dumps(desired_attributes.get("attributes")) + ) ) if desired_attributes.get("update_attributes"): @@ -490,9 +494,7 @@ def _detect_changes_attributes(self): a for a in tmp_remove_attributes if current_attributes.get(a) ] if len(removes_which) > 0: - changes.append( - "remove attributes: %s" % " ".join(removes_which) - ) + changes.append("remove attributes: %s" % " ".join(removes_which)) elif isinstance(tmp_remove_attributes, dict): if not self.extended_functionality: self.module.fail_json( @@ -521,9 +523,7 @@ def _detect_changes_attributes(self): desired_attributes.pop("remove_attributes", {}) if tmp_remove != {}: - changes.append( - "remove attributes: %s" % json.dumps(tmp_remove) - ) + changes.append("remove attributes: %s" % json.dumps(tmp_remove)) if tmp_rest != {}: desired_attributes["update_attributes"] = tmp_rest else: @@ -730,7 +730,9 @@ def _edit_attributes(self): data.pop(key, "") result = self._fetch( - code_mapping=(HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit), + code_mapping=( + HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit + ), endpoint=self._build_default_endpoint(), data=data, method="PUT", From 6ca05051f6e4ece46b58b44c849db1855fd3cd88 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 12:09:16 +0100 Subject: [PATCH 060/117] fix: style --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 35063369a..432e5a3f5 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -469,7 +469,7 @@ def _detect_changes_attributes(self): "attributes: %s %s" % ( json.dumps(current_attributes), - json.dumps(desired_attributes.get("attributes")) + json.dumps(desired_attributes.get("attributes")), ) ) From a60d4331930e205a9b43976aab8ea371124459a8 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 12:19:57 +0100 Subject: [PATCH 061/117] add: extend tests --- tests/integration/targets/host/tasks/test.yml | 390 ++++++++++++++++++ tests/integration/targets/host/vars/main.yml | 47 +++ 2 files changed, 437 insertions(+) diff --git a/tests/integration/targets/host/tasks/test.yml b/tests/integration/targets/host/tasks/test.yml index 89a904157..32c0deef2 100644 --- a/tests/integration/targets/host/tasks/test.yml +++ b/tests/integration/targets/host/tasks/test.yml @@ -140,6 +140,396 @@ run_once: true # noqa run-once[task] loop: "{{ checkmk_hosts }}" +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +### Cluster Host Tests +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create hosts." + host: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + nodes: "{{ item.nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency of create cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + nodes: "{{ item.nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Modify nodes in cluster host." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ first.name }}" + folder: "{{ first.folder }}" + nodes: "{{ second.nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + vars: + first: "{{ checkmk_cluster_hosts[0] }}" + second: "{{ checkmk_cluster_hosts[1] }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency, Modify nodes in cluster host." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ first.name }}" + folder: "{{ first.folder }}" + nodes: "{{ second.nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + vars: + first: "{{ checkmk_cluster_hosts[0] }}" + second: "{{ checkmk_cluster_hosts[1] }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Add nodes to cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + add_nodes: "{{ item.add_nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts_add_nodes }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency of Add nodes to cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + add_nodes: "{{ item.add_nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts_add_nodes }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Remove nodes to cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + rmove_nodes: "{{ item.remove_nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts_remove_nodes }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Cehck idempotency of Remove nodes to cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + remove_nodes: "{{ item.remove_nodes }}" + attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts_remove_nodes }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +### +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete cluster hosts." + host: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + state: "absent" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency of delete cluster hosts." + host: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + state: "absent" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create cluster host with update_attributes without folder." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + nodes: "{{ item.nodes }}" + update_attributes: + site: "{{ outer_item.site }}" + ipaddress: 127.0.0.1 + labels: + foo: bar + alias: test + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency on update_attributes for only a subset of attributes." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + nodes: "{{ item.nodes }}" + update_attributes: + labels: + foo: bar + alias: test + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Remove Attributes of cluster host." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + nodes: "{{ item.nodes }}" + remove_attributes: + - alias + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency on remove_attributes." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + nodes: "{{ item.nodes }}" + remove_attributes: + - alias + state: "present" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete cluster hosts." + cluster: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + nodes: "{{ item.nodes }}" + folder: "{{ item.folder }}" + state: "absent" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_cluster_hosts }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete hosts." + host: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + name: "{{ item.name }}" + folder: "{{ item.folder }}" + state: "absent" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_hosts }}" + + + + + + - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete folders." folder: server_url: "{{ checkmk_var_server_url }}" diff --git a/tests/integration/targets/host/vars/main.yml b/tests/integration/targets/host/vars/main.yml index 239cd82ac..bd44a96f8 100644 --- a/tests/integration/targets/host/vars/main.yml +++ b/tests/integration/targets/host/vars/main.yml @@ -34,3 +34,50 @@ checkmk_hosts: folder: "/foo/bar" - name: test5.tld folder: "/foo/bar1" + +checkmk_cluster_hosts: + - name: cluster_test1.tld + folder: "/" + nodes: + - "test1.tld" + - "test2.tld" + - name: cluster_test2.tld + folder: "/" + nodes: + - "test3.tld" + - name: cluster_test3.tld + folder: "/" + nodes: "test4.tld" + +checkmk_cluster_hosts_add_nodes: + - name: cluster_test1.tld + folder: "/" + add_nodes: + - "test1.tld" + - "test2.tld" + - "test3.tld" + - "test4.tld" + - name: cluster_test2.tld + folder: "/" + add_nodes: + - "test2.tld" + - "test3.tld" + - name: cluster_test3.tld + folder: "/" + add_nodes: + - "test3.tld" + - "test4.tld" + +checkmk_cluster_hosts_remove_nodes: + - name: cluster_test1.tld + folder: "/" + remove_nodes: + - "test3.tld" + - "test4.tld" + - name: cluster_test2.tld + folder: "/" + remove_nodes: + - "test2.tld" + - name: cluster_test3.tld + folder: "/" + remove_nodes: "test3.tld" From 56bf47c00f499bc010571ab91ace7809061f4427 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 12:24:54 +0100 Subject: [PATCH 062/117] fix: style --- tests/integration/targets/host/tasks/test.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/integration/targets/host/tasks/test.yml b/tests/integration/targets/host/tasks/test.yml index 32c0deef2..8c6e8ce0c 100644 --- a/tests/integration/targets/host/tasks/test.yml +++ b/tests/integration/targets/host/tasks/test.yml @@ -525,11 +525,7 @@ run_once: true # noqa run-once[task] loop: "{{ checkmk_hosts }}" - - - - - +### - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete folders." folder: server_url: "{{ checkmk_var_server_url }}" From d6e10cfcb02e4da3619c2951f5573a5bcc2918a3 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 15:34:37 +0100 Subject: [PATCH 063/117] refactor: is_cluster field --- plugins/modules/host.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 432e5a3f5..5d9e3c32d 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -581,10 +581,7 @@ def _get_current(self): self.etag = result.etag - if self.current.get("cluster_nodes"): - self.is_cluster = True - else: - self.is_cluster = False + self.is_cluster = self.current.get("is_cluster"): else: self.state = "absent" From 6fee1577a4ea678e5e425038e91e3fc1602b7527 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 18:17:32 +0100 Subject: [PATCH 064/117] fix: typo --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 5d9e3c32d..de700a0de 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -581,7 +581,7 @@ def _get_current(self): self.etag = result.etag - self.is_cluster = self.current.get("is_cluster"): + self.is_cluster = self.current.get("is_cluster") else: self.state = "absent" From 446757925f5350400f6fa9fbeb614829979b6ce1 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 23:22:55 +0100 Subject: [PATCH 065/117] cleanup: --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index de700a0de..17f1a14c7 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -652,7 +652,7 @@ def _edit_folder(self): ) result = result._replace( - msg=result.msg + ". Moved from to: %s" % tmp.get("target_folder") + msg=result.msg + ". Moved to: %s" % tmp.get("target_folder") ) return result From 0cfecf3b90e2559f6948254e6edb323c2a48c1e0 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 21 Feb 2024 23:26:47 +0100 Subject: [PATCH 066/117] fix: folder title treatment --- plugins/modules/folder.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index ea2500b79..8a50d5fc2 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -31,7 +31,7 @@ required: true type: str name: - description: The name of your folder. If omitted defaults to the folder name. + description: The name (title) of your folder. If omitted defaults to the folder-name from path. type: str aliases: [title] attributes: @@ -220,7 +220,11 @@ def __init__(self, module): (self.desired["parent"], self.desired["name"]) = self._normalize_path( self.params.get("path") ) - self.desired["title"] = self.params.get("title", self.desired["name"]) + + if self.params.get("title"): + self.desired["title"] = self.params.get("name") + else: + self.desired["title"] = self.desired.get("name") for key in FOLDER: if self.params.get(key): From 791cd624760ea82d280dac953a19db43bd299daa Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 09:59:52 +0100 Subject: [PATCH 067/117] cleanup: --- plugins/modules/host.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 17f1a14c7..8a08b6e62 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -401,7 +401,7 @@ def _detect_changes_folder(self): if desired_folder and current_folder and current_folder != desired_folder: changes.append("folder") else: - self.desired.pop("folder", "") + self.desired.pop("folder", None) return changes @@ -419,24 +419,25 @@ def _detect_changes_rename(self): def _detect_changes_nodes(self): changes = [] + desired_parameters = self.desired.copy() current_nodes = [] if self.current.get("cluster_nodes"): current_nodes = self.current.get("cluster_nodes") if ( - self.desired.get("nodes") - or self.desired.get("add_nodes") - or self.desired.get("remove_nodes") + desired_parameters.get("nodes") + or desired_parameters.get("add_nodes") + or desired_parameters.get("remove_nodes") ): - desired_nodes = self.desired.get("nodes", []) + desired_nodes = desired_parameters.get("nodes", []) - desired_nodes = desired_nodes + self.desired.get("add_nodes", []) + desired_nodes = desired_nodes + desired_parameters.get("add_nodes", []) desired_nodes = [ el for el in desired_nodes - if el not in self.desired.get("remove_nodes", []) + if el not in desired_parameters.get("remove_nodes", []) ] if ( @@ -445,9 +446,9 @@ def _detect_changes_nodes(self): ): changes.append("nodes") else: - self.desired.pop("nodes", []) - self.desired.pop("add_nodes", []) - self.desired.pop("remove_nodes", []) + self.desired.pop("nodes", None) + self.desired.pop("add_nodes", None) + self.desired.pop("remove_nodes", None) return changes @@ -521,7 +522,7 @@ def _detect_changes_attributes(self): exception=e, ) - desired_attributes.pop("remove_attributes", {}) + desired_attributes.pop("remove_attributes", None) if tmp_remove != {}: changes.append("remove attributes: %s" % json.dumps(tmp_remove)) if tmp_rest != {}: @@ -537,7 +538,7 @@ def _detect_changes_attributes(self): if desired_attributes.get(key): self.desired[key] = desired_attributes.get(key) else: - self.desired.pop(key, "") + self.desired.pop(key, None) return changes @@ -724,7 +725,7 @@ def _edit_attributes(self): ] for key in CLEAN_FIELDS: - data.pop(key, "") + data.pop(key, None) result = self._fetch( code_mapping=( From 8b8392b7bbfdc2391bb3409e4db54655111e7ee4 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 10:00:34 +0100 Subject: [PATCH 068/117] extend: test suite --- .../integration/targets/folder/tasks/test.yml | 68 +++++++++++++++++++ .../integration/targets/folder/vars/main.yml | 10 +++ 2 files changed, 78 insertions(+) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index 65eb9016f..f07b19597 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -158,3 +158,71 @@ - "{{ outer_item.site }}" delegate_to: localhost run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create folders for defaults test." + folder: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + path: "{{ item.path }}" + name: "{{ item.name | default(omit) }}" + state: "present" + loop: "{{ checkmk_var_folders_defaults_test }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." + ansible.builtin.assert: + that: "results.title == item.verify_name" + vars: + results: "{{ lookup('checkmk.general.folder', + item.path, + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}" + loop: "{{ checkmk_var_folders_defaults_test }}" + fail_msg: "Creted folders title does not match to the expected one!" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete folders." + folder: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + path: "{{ item.path }}" + name: "{{ item.name | default(omit) }}" + state: "absent" + loop: "{{ checkmk_var_folders_defaults_test }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + loop: "{{ checkmk_var_folders }}" + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." + activation: + server_url: "{{ checkmk_var_server_url }}" + site: "{{ outer_item.site }}" + automation_user: "{{ checkmk_var_automation_user }}" + automation_secret: "{{ checkmk_var_automation_secret }}" + force_foreign_changes: true + sites: + - "{{ outer_item.site }}" + delegate_to: localhost + run_once: true # noqa run-once[task] diff --git a/tests/integration/targets/folder/vars/main.yml b/tests/integration/targets/folder/vars/main.yml index 30d015abd..958cea01b 100644 --- a/tests/integration/targets/folder/vars/main.yml +++ b/tests/integration/targets/folder/vars/main.yml @@ -35,3 +35,13 @@ checkmk_folder_attr_test: attributes: tag_criticality: "test" tag_networking: "dmz" + +checkmk_var_folders_defaults_test: + - path: /foo + verify_name: "foo" + - path: /foo/bar + name: Bar + verify_name: "Bar" + - path: /foo/bar/tresure + verify_name: "treasure" + From d67e0213457999f4b0680a793bcde905f24da817 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 10:06:41 +0100 Subject: [PATCH 069/117] extend: test suite --- tests/integration/targets/folder/tasks/test.yml | 1 - tests/integration/targets/folder/vars/main.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index f07b19597..afbff5114 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -213,7 +213,6 @@ loop: "{{ checkmk_var_folders_defaults_test }}" delegate_to: localhost run_once: true # noqa run-once[task] - loop: "{{ checkmk_var_folders }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate." activation: diff --git a/tests/integration/targets/folder/vars/main.yml b/tests/integration/targets/folder/vars/main.yml index 958cea01b..8e9503e33 100644 --- a/tests/integration/targets/folder/vars/main.yml +++ b/tests/integration/targets/folder/vars/main.yml @@ -44,4 +44,3 @@ checkmk_var_folders_defaults_test: verify_name: "Bar" - path: /foo/bar/tresure verify_name: "treasure" - From 3533228c8fdc39dc68ee304177c5f22c21a08f6a Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 10:15:38 +0100 Subject: [PATCH 070/117] fix: --- tests/integration/targets/folder/tasks/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index afbff5114..d667103ba 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -197,7 +197,6 @@ automation_secret=checkmk_var_automation_secret) }}" loop: "{{ checkmk_var_folders_defaults_test }}" - fail_msg: "Creted folders title does not match to the expected one!" delegate_to: localhost run_once: true # noqa run-once[task] From f7a74a2c20a0f33c7d7fbd2431a627c2513374f4 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 10:40:27 +0100 Subject: [PATCH 071/117] fix: --- tests/integration/targets/folder/tasks/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index d667103ba..dd649b40e 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,7 +186,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "results.title == item.verify_name" + that: "results.name == item.verify_name" vars: results: "{{ lookup('checkmk.general.folder', item.path, From 127864682e7910ea0f313a925a33fb8983ea0158 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 11:38:47 +0100 Subject: [PATCH 072/117] fix: with folders lookup --- tests/integration/targets/folder/tasks/test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index dd649b40e..d95b2d249 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,16 +186,17 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "results.name == item.verify_name" + that: "folder_title[item.path | regex_replace('/', '~')] == item.verify_name" vars: - results: "{{ lookup('checkmk.general.folder', - item.path, + results: "{{ lookup('checkmk.general.folders', + '~', server_url=checkmk_var_server_url, site=outer_item.site, validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) }}" + folder_title: "{{ dict((results | map(attribute='id')) | zip(results | map(attribute='title'))) }}" loop: "{{ checkmk_var_folders_defaults_test }}" delegate_to: localhost run_once: true # noqa run-once[task] From c5ed153ed836bb83079b855ba9d0f9e25dab3b8c Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 11:53:22 +0100 Subject: [PATCH 073/117] fix: add hack --- tests/integration/targets/folder/tasks/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index d95b2d249..d297f7a7c 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,7 +186,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "folder_title[item.path | regex_replace('/', '~')] == item.verify_name" + that: "folder_title['~' + (item.path | regex_replace('/', '~') | split('~') | last)] == item.verify_name" vars: results: "{{ lookup('checkmk.general.folders', '~', From 2f2ec07d390e90515636aed28b265c46b8b37c4f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 13:48:00 +0100 Subject: [PATCH 074/117] fix: --- tests/integration/targets/folder/tasks/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index d297f7a7c..dfc72cd4f 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,7 +186,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "folder_title['~' + (item.path | regex_replace('/', '~') | split('~') | last)] == item.verify_name" + that: "folder_title[item.path] == item.verify_name" vars: results: "{{ lookup('checkmk.general.folders', '~', @@ -196,7 +196,7 @@ automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) }}" - folder_title: "{{ dict((results | map(attribute='id')) | zip(results | map(attribute='title'))) }}" + folder_title: "{{ dict((results | map(attribute='id') | map('regex_replace', '/', '~')) | zip(results | map(attribute='title'))) }}" loop: "{{ checkmk_var_folders_defaults_test }}" delegate_to: localhost run_once: true # noqa run-once[task] From aab269b6443117dfb9dea31e055df6051c1df624 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 13:54:32 +0100 Subject: [PATCH 075/117] fix: --- tests/integration/targets/folder/tasks/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index dfc72cd4f..905b6f99d 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,7 +186,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "folder_title[item.path] == item.verify_name" + that: "folder_title[item.path | regex_replace('/', '~') ] == item.verify_name" vars: results: "{{ lookup('checkmk.general.folders', '~', From 29f58119980f0efaeb169488af657fd3c7f34550 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 14:00:53 +0100 Subject: [PATCH 076/117] fix: logic --- tests/integration/targets/folder/tasks/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index 905b6f99d..9290d1ef4 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -186,7 +186,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: - that: "folder_title[item.path | regex_replace('/', '~') ] == item.verify_name" + that: "folder_title[item.path | regex_replace('~', '/') ] == item.verify_name" vars: results: "{{ lookup('checkmk.general.folders', '~', @@ -196,7 +196,7 @@ automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) }}" - folder_title: "{{ dict((results | map(attribute='id') | map('regex_replace', '/', '~')) | zip(results | map(attribute='title'))) }}" + folder_title: "{{ dict((results | map(attribute='id') | map('regex_replace', '~', '/')) | zip(results | map(attribute='title'))) }}" loop: "{{ checkmk_var_folders_defaults_test }}" delegate_to: localhost run_once: true # noqa run-once[task] From 21fd8c843cb0cca1d6b42ac329437f7ea5780ce2 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 14:08:26 +0100 Subject: [PATCH 077/117] refactor: simplify test --- tests/integration/targets/folder/vars/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/targets/folder/vars/main.yml b/tests/integration/targets/folder/vars/main.yml index 8e9503e33..3b406f7f4 100644 --- a/tests/integration/targets/folder/vars/main.yml +++ b/tests/integration/targets/folder/vars/main.yml @@ -39,8 +39,6 @@ checkmk_folder_attr_test: checkmk_var_folders_defaults_test: - path: /foo verify_name: "foo" - - path: /foo/bar + - path: /bar name: Bar verify_name: "Bar" - - path: /foo/bar/tresure - verify_name: "treasure" From 1a5800d37af163c91d7da25161a2b29e837c43d2 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 14:17:45 +0100 Subject: [PATCH 078/117] test: --- tests/integration/targets/folder/tasks/test.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/integration/targets/folder/tasks/test.yml b/tests/integration/targets/folder/tasks/test.yml index 9290d1ef4..b425d7f01 100644 --- a/tests/integration/targets/folder/tasks/test.yml +++ b/tests/integration/targets/folder/tasks/test.yml @@ -184,6 +184,22 @@ delegate_to: localhost run_once: true # noqa run-once[task] +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Print created folders." + ansible.builtin.debug: + var: folder_title + vars: + results: "{{ lookup('checkmk.general.folders', + '~', + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}" + folder_title: "{{ dict((results | map(attribute='id') | map('regex_replace', '~', '/')) | zip(results | map(attribute='title'))) }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify created folders." ansible.builtin.assert: that: "folder_title[item.path | regex_replace('~', '/') ] == item.verify_name" From 66302786e8088662d797be35d61e28f3af1d8871 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 22 Feb 2024 14:30:05 +0100 Subject: [PATCH 079/117] fix: again copy pase error --- plugins/modules/folder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index 8a50d5fc2..139e2a14b 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -221,7 +221,7 @@ def __init__(self, module): self.params.get("path") ) - if self.params.get("title"): + if self.params.get("name"): self.desired["title"] = self.params.get("name") else: self.desired["title"] = self.desired.get("name") From 5bd9f000b112aaebcf8ee37400983ba4bfa2242b Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Fri, 1 Mar 2024 14:00:23 +0100 Subject: [PATCH 080/117] change: changed status for check mode --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 8a08b6e62..20ff06d93 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -594,7 +594,7 @@ def _check_output(self, mode): content="", etag="", failed=False, - changed=False, + changed=True, ) def needs_update(self): From 6fff122a34f7e03a2514b9f00ca8c5e0e3f806a2 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Fri, 1 Mar 2024 14:01:35 +0100 Subject: [PATCH 081/117] change: changed status for check mode --- plugins/modules/folder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index 139e2a14b..d955c0e66 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -403,7 +403,7 @@ def _check_output(self, mode): content="", etag="", failed=False, - changed=False, + changed=True, ) def needs_update(self): From 7795b1c38e9f93fc0fafe2b76c7810d7f4482d0c Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Fri, 1 Mar 2024 14:02:25 +0100 Subject: [PATCH 082/117] change: changed status for check mode --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 697678d79..9d9908d51 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -430,7 +430,7 @@ def _check_output(self, mode): content="", etag="", failed=False, - changed=False, + changed=True, ) def needs_update(self): From 2c5256f7639547e0427452017ad390633f4e6fc6 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 5 Mar 2024 15:26:35 -0500 Subject: [PATCH 083/117] Bump Checkmk versions. --- roles/agent/README.md | 2 +- roles/agent/defaults/main.yml | 2 +- roles/agent/molecule/2.1.0/group_vars/all.yml | 2 +- roles/agent/molecule/2.2.0/group_vars/all.yml | 2 +- roles/server/README.md | 2 +- roles/server/defaults/main.yml | 2 +- roles/server/molecule/2.1.0/group_vars/all.yml | 2 +- roles/server/molecule/2.2.0/group_vars/all.yml | 2 +- scripts/release.sh | 4 ++-- tests/integration/targets/activation/vars/main.yml | 6 +++--- tests/integration/targets/bakery/vars/main.yml | 4 ++-- tests/integration/targets/contact_group/vars/main.yml | 6 +++--- tests/integration/targets/discovery/vars/main.yml | 6 +++--- tests/integration/targets/downtime/vars/main.yml | 6 +++--- tests/integration/targets/folder/vars/main.yml | 6 +++--- tests/integration/targets/host/vars/main.yml | 6 +++--- tests/integration/targets/host_group/vars/main.yml | 8 ++++---- tests/integration/targets/lookup_bakery/vars/main.yml | 4 ++-- tests/integration/targets/lookup_folder/vars/main.yml | 6 +++--- tests/integration/targets/lookup_folders/vars/main.yml | 6 +++--- tests/integration/targets/lookup_host/vars/main.yml | 6 +++--- tests/integration/targets/lookup_hosts/vars/main.yml | 6 +++--- tests/integration/targets/lookup_rules/vars/main.yml | 6 +++--- tests/integration/targets/lookup_rulesets/vars/main.yml | 6 +++--- tests/integration/targets/lookup_version/vars/main.yml | 6 +++--- tests/integration/targets/password/vars/main.yml | 8 ++++---- tests/integration/targets/rule/vars/main.yml | 6 +++--- tests/integration/targets/service_group/vars/main.yml | 8 ++++---- tests/integration/targets/tag_group/vars/main.yml | 8 ++++---- tests/integration/targets/timeperiod/vars/main.yml | 6 +++--- tests/integration/targets/user/vars/main.yml | 8 ++++---- 31 files changed, 79 insertions(+), 79 deletions(-) diff --git a/roles/agent/README.md b/roles/agent/README.md index cb7d55538..1d28cd07f 100644 --- a/roles/agent/README.md +++ b/roles/agent/README.md @@ -13,7 +13,7 @@ It can be installed as easy as running: ## Role Variables - checkmk_agent_version: "2.2.0p22" + checkmk_agent_version: "2.2.0p23" The Checkmk version of the site your agents will talk to. diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml index d99c3a1f1..e43d0f13a 100644 --- a/roles/agent/defaults/main.yml +++ b/roles/agent/defaults/main.yml @@ -1,5 +1,5 @@ --- -checkmk_agent_version: "2.2.0p22" +checkmk_agent_version: "2.2.0p23" checkmk_agent_edition: cre checkmk_agent_server_protocol: http checkmk_agent_server: localhost diff --git a/roles/agent/molecule/2.1.0/group_vars/all.yml b/roles/agent/molecule/2.1.0/group_vars/all.yml index 23df43011..1437d561b 100644 --- a/roles/agent/molecule/2.1.0/group_vars/all.yml +++ b/roles/agent/molecule/2.1.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.1.0p39" +checkmk_var_version: "2.1.0p40" checkmk_var_edition: "cre" checkmk_var_checkmk_site: "my_site" checkmk_var_automation_user: "cmkadmin" diff --git a/roles/agent/molecule/2.2.0/group_vars/all.yml b/roles/agent/molecule/2.2.0/group_vars/all.yml index 2d9a1d6d6..6a8503c5c 100644 --- a/roles/agent/molecule/2.2.0/group_vars/all.yml +++ b/roles/agent/molecule/2.2.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.2.0p22" +checkmk_var_version: "2.2.0p23" checkmk_var_edition: "cre" checkmk_var_checkmk_site: "my_site" checkmk_var_automation_user: "cmkadmin" diff --git a/roles/server/README.md b/roles/server/README.md index 3d679da43..f4e69f6aa 100644 --- a/roles/server/README.md +++ b/roles/server/README.md @@ -25,7 +25,7 @@ To learn about the distributions used in automated tests, inspect the correspond ## Role Variables - checkmk_server_version: "2.2.0p22" + checkmk_server_version: "2.2.0p23" The global Checkmk version. This is used for installing Checkmk. To manage sites and their version, see `checkmk_server_sites`. diff --git a/roles/server/defaults/main.yml b/roles/server/defaults/main.yml index 62e6dd721..a7a084093 100644 --- a/roles/server/defaults/main.yml +++ b/roles/server/defaults/main.yml @@ -24,7 +24,7 @@ checkmk_server_server_stable_os: - Ubuntu-20 - Ubuntu-22 -checkmk_server_version: "2.2.0p22" +checkmk_server_version: "2.2.0p23" checkmk_server_edition: cre checkmk_server_verify_setup: 'true' diff --git a/roles/server/molecule/2.1.0/group_vars/all.yml b/roles/server/molecule/2.1.0/group_vars/all.yml index 8baa9a637..62c495f0e 100644 --- a/roles/server/molecule/2.1.0/group_vars/all.yml +++ b/roles/server/molecule/2.1.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.1.0p39" +checkmk_var_version: "2.1.0p40" checkmk_var_edition: "cre" checkmk_server_verify_setup: 'true' checkmk_var_server_url: "http://127.0.0.1/" diff --git a/roles/server/molecule/2.2.0/group_vars/all.yml b/roles/server/molecule/2.2.0/group_vars/all.yml index 902bdc3ae..a65cf8c29 100644 --- a/roles/server/molecule/2.2.0/group_vars/all.yml +++ b/roles/server/molecule/2.2.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.2.0p22" +checkmk_var_version: "2.2.0p23" checkmk_var_edition: "cre" checkmk_server_verify_setup: 'true' checkmk_var_server_url: "http://127.0.0.1/" diff --git a/scripts/release.sh b/scripts/release.sh index 328c6b1a4..6342e3fc8 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -16,8 +16,8 @@ collection_dir="${script_dir%/*}" # Update these as necessary: checkmk_ancient="2.0.0p39" -checkmk_oldstable="2.1.0p39" -checkmk_stable="2.2.0p22" +checkmk_oldstable="2.1.0p40" +checkmk_stable="2.2.0p23" while getopts 's:t:' OPTION; do case "$OPTION" in diff --git a/tests/integration/targets/activation/vars/main.yml b/tests/integration/targets/activation/vars/main.yml index f55a7fb56..91e8ed7ad 100644 --- a/tests/integration/targets/activation/vars/main.yml +++ b/tests/integration/targets/activation/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/bakery/vars/main.yml b/tests/integration/targets/bakery/vars/main.yml index f390261b6..2d72d28d5 100644 --- a/tests/integration/targets/bakery/vars/main.yml +++ b/tests/integration/targets/bakery/vars/main.yml @@ -1,9 +1,9 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cee" site: "old_cee" diff --git a/tests/integration/targets/contact_group/vars/main.yml b/tests/integration/targets/contact_group/vars/main.yml index 124c01d29..f851cd39c 100644 --- a/tests/integration/targets/contact_group/vars/main.yml +++ b/tests/integration/targets/contact_group/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/discovery/vars/main.yml b/tests/integration/targets/discovery/vars/main.yml index 53e43630a..34512dca5 100644 --- a/tests/integration/targets/discovery/vars/main.yml +++ b/tests/integration/targets/discovery/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/downtime/vars/main.yml b/tests/integration/targets/downtime/vars/main.yml index f55a7fb56..91e8ed7ad 100644 --- a/tests/integration/targets/downtime/vars/main.yml +++ b/tests/integration/targets/downtime/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/folder/vars/main.yml b/tests/integration/targets/folder/vars/main.yml index 30d015abd..798d8fdf1 100644 --- a/tests/integration/targets/folder/vars/main.yml +++ b/tests/integration/targets/folder/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/host/vars/main.yml b/tests/integration/targets/host/vars/main.yml index 239cd82ac..c1cff38fa 100644 --- a/tests/integration/targets/host/vars/main.yml +++ b/tests/integration/targets/host/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/host_group/vars/main.yml b/tests/integration/targets/host_group/vars/main.yml index f6facb348..ea40fab2c 100644 --- a/tests/integration/targets/host_group/vars/main.yml +++ b/tests/integration/targets/host_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cme" site: "stable_cme" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_bakery/vars/main.yml b/tests/integration/targets/lookup_bakery/vars/main.yml index 3809fd273..bddbccdff 100644 --- a/tests/integration/targets/lookup_bakery/vars/main.yml +++ b/tests/integration/targets/lookup_bakery/vars/main.yml @@ -1,8 +1,8 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cee" site: "old_cee" diff --git a/tests/integration/targets/lookup_folder/vars/main.yml b/tests/integration/targets/lookup_folder/vars/main.yml index 6fed2d247..46475a44b 100644 --- a/tests/integration/targets/lookup_folder/vars/main.yml +++ b/tests/integration/targets/lookup_folder/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_folders/vars/main.yml b/tests/integration/targets/lookup_folders/vars/main.yml index f838892b0..e738dac4b 100644 --- a/tests/integration/targets/lookup_folders/vars/main.yml +++ b/tests/integration/targets/lookup_folders/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_host/vars/main.yml b/tests/integration/targets/lookup_host/vars/main.yml index 3b5e6be7f..cd18b47b3 100644 --- a/tests/integration/targets/lookup_host/vars/main.yml +++ b/tests/integration/targets/lookup_host/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_hosts/vars/main.yml b/tests/integration/targets/lookup_hosts/vars/main.yml index c370444f5..6b443cd28 100644 --- a/tests/integration/targets/lookup_hosts/vars/main.yml +++ b/tests/integration/targets/lookup_hosts/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_rules/vars/main.yml b/tests/integration/targets/lookup_rules/vars/main.yml index 5f85c1230..10c7b2387 100644 --- a/tests/integration/targets/lookup_rules/vars/main.yml +++ b/tests/integration/targets/lookup_rules/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/lookup_rulesets/vars/main.yml b/tests/integration/targets/lookup_rulesets/vars/main.yml index cef6b9a8a..497ef4d06 100644 --- a/tests/integration/targets/lookup_rulesets/vars/main.yml +++ b/tests/integration/targets/lookup_rulesets/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/lookup_version/vars/main.yml b/tests/integration/targets/lookup_version/vars/main.yml index a622b3980..12e5f3e2d 100644 --- a/tests/integration/targets/lookup_version/vars/main.yml +++ b/tests/integration/targets/lookup_version/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/password/vars/main.yml b/tests/integration/targets/password/vars/main.yml index ad69bd9f9..b61b76dd1 100644 --- a/tests/integration/targets/password/vars/main.yml +++ b/tests/integration/targets/password/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cme" site: "stable_cme" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/rule/vars/main.yml b/tests/integration/targets/rule/vars/main.yml index 9a019eb6e..cee5dc35d 100644 --- a/tests/integration/targets/rule/vars/main.yml +++ b/tests/integration/targets/rule/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/service_group/vars/main.yml b/tests/integration/targets/service_group/vars/main.yml index 7b7b69f17..69dd7d45a 100644 --- a/tests/integration/targets/service_group/vars/main.yml +++ b/tests/integration/targets/service_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cme" site: "stable_cme" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/tag_group/vars/main.yml b/tests/integration/targets/tag_group/vars/main.yml index c8cd69b17..2f9a970df 100644 --- a/tests/integration/targets/tag_group/vars/main.yml +++ b/tests/integration/targets/tag_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cme" site: "stable_cme" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/timeperiod/vars/main.yml b/tests/integration/targets/timeperiod/vars/main.yml index 58d8a131b..2f1fe09fb 100644 --- a/tests/integration/targets/timeperiod/vars/main.yml +++ b/tests/integration/targets/timeperiod/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/user/vars/main.yml b/tests/integration/targets/user/vars/main.yml index 3da150a1c..40e3cb361 100644 --- a/tests/integration/targets/user/vars/main.yml +++ b/tests/integration/targets/user/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cme" site: "stable_cme" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cre" site: "stable_cre" - - version: "2.2.0p22" + - version: "2.2.0p23" edition: "cee" site: "stable_cee" - - version: "2.1.0p39" + - version: "2.1.0p40" edition: "cre" site: "old_cre" From 7ea95c74296a330293ab48a0db1b49a39eac1583 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 06:28:48 +0000 Subject: [PATCH 084/117] Bump softprops/action-gh-release from 1 to 2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fc6e7a3b3..c8ad39b7b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -132,7 +132,7 @@ jobs: - name: Create Release and upload Assets id: create-release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: token: ${{ secrets.GITHUB_TOKEN }} draft: false From b70ea20db0eed34ef965488a1e3731ba81583fdd Mon Sep 17 00:00:00 2001 From: Sebastien Laithier Date: Tue, 12 Mar 2024 09:45:22 +0100 Subject: [PATCH 085/117] Updating lookup exemple --- docs/version_lookup.rst | 5 +++-- plugins/lookup/version.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/version_lookup.rst b/docs/version_lookup.rst index 7d815c5a4..3dd9b6419 100644 --- a/docs/version_lookup.rst +++ b/docs/version_lookup.rst @@ -385,13 +385,14 @@ Examples .. code-block:: yaml+jinja - + - name: "Show Checkmk version" debug: msg: "Server version is {{ version }}" vars: version: "{{ lookup('checkmk.general.version', - server_url + '/' + site, + server_url=my_url, + site=my_site, validate_certs=False, automation_user=my_user, automation_secret=my_secret diff --git a/plugins/lookup/version.py b/plugins/lookup/version.py index 389876af2..a6949ef22 100644 --- a/plugins/lookup/version.py +++ b/plugins/lookup/version.py @@ -89,7 +89,8 @@ msg: "Server version is {{ version }}" vars: version: "{{ lookup('checkmk.general.version', - server_url + '/' + site, + server_url=my_url, + site=my_site, validate_certs=False, automation_user=my_user, automation_secret=my_secret From d66822e2ab26c54b1eef707e05a459978c409f47 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:59:36 +0000 Subject: [PATCH 086/117] Bump black from 22.3.0 to 24.3.0 Bumps [black](https://github.com/psf/black) from 22.3.0 to 24.3.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/22.3.0...24.3.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements-qa.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-qa.txt b/requirements-qa.txt index ef2b610e8..dba4b97be 100644 --- a/requirements-qa.txt +++ b/requirements-qa.txt @@ -1,4 +1,4 @@ -black==22.3.0 +black==24.3.0 click==8.1.3 isort==5.10.1 mypy-extensions==0.4.3 From b0fa7a91c2f104c015b51622e13ec4e8de64e290 Mon Sep 17 00:00:00 2001 From: thorian93 Date: Sat, 23 Mar 2024 15:32:53 -0400 Subject: [PATCH 087/117] Clean up release.yaml. --- .github/workflows/release.yaml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c8ad39b7b..32f1d7bfb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,14 +1,15 @@ --- - -env: - NAMESPACE: checkmk - COLLECTION_NAME: general - name: Release Collection on: # yamllint disable-line rule:truthy workflow_dispatch: +env: + NAMESPACE: checkmk + COLLECTION_NAME: general + FILES: "ansible.cfg CHANGELOG.rst galaxy.yml LICENSE README.md" + DIRS: "changelogs docs meta playbooks plugins roles" + jobs: # @@ -83,8 +84,8 @@ jobs: cp $files build/src cp -rf $directories build/src env: - files: "ansible.cfg CHANGELOG.rst galaxy.yml LICENSE README.md" - directories: "changelogs docs meta playbooks plugins roles" + files: ${{env.FILES}} + directories: ${{env.DIRS}} - name: Build Ansible Collection run: ansible-galaxy collection build build/src --force @@ -103,7 +104,7 @@ jobs: with: commit-message: Update Docs and Changelogs upon Release signoff: false - branch: changelogs-docs-update-devel + branch: changelogs-docs-update-${{ steps.current_version.outputs.version }} base: devel delete-branch: true title: '[Auto] Update changelogs and docs upon release' @@ -124,8 +125,8 @@ jobs: cp -rf $directories build/src rm -rf build/src/roles/*/molecule env: - files: "CHANGELOG.rst LICENSE README.md ansible.cfg galaxy.yml" - directories: "changelogs docs meta playbooks plugins roles" + files: ${{env.FILES}} + directories: ${{env.DIRS}} - name: Build Ansible Collection run: ansible-galaxy collection build build/src --force From 953fc23636d1f05be2251a8e03be60749513c0ab Mon Sep 17 00:00:00 2001 From: thorian93 Date: Sat, 23 Mar 2024 15:33:17 -0400 Subject: [PATCH 088/117] Comment unnecessary tests. --- roles/agent/molecule/2.0.0/molecule.yml | 2 +- roles/agent/molecule/2.1.0/molecule.yml | 2 +- roles/agent/molecule/2.2.0/molecule.yml | 2 +- roles/server/molecule/2.0.0/molecule.yml | 2 +- roles/server/molecule/2.1.0/molecule.yml | 2 +- roles/server/molecule/2.2.0/molecule.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml index 855cb0840..363d0b3ea 100644 --- a/roles/agent/molecule/2.0.0/molecule.yml +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -97,7 +97,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml index 47f80c03e..8e4540820 100644 --- a/roles/agent/molecule/2.1.0/molecule.yml +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -72,7 +72,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml index 47f80c03e..8e4540820 100644 --- a/roles/agent/molecule/2.2.0/molecule.yml +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -72,7 +72,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy diff --git a/roles/server/molecule/2.0.0/molecule.yml b/roles/server/molecule/2.0.0/molecule.yml index 29383e10f..333a2f95b 100644 --- a/roles/server/molecule/2.0.0/molecule.yml +++ b/roles/server/molecule/2.0.0/molecule.yml @@ -74,7 +74,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy diff --git a/roles/server/molecule/2.1.0/molecule.yml b/roles/server/molecule/2.1.0/molecule.yml index 47f80c03e..8e4540820 100644 --- a/roles/server/molecule/2.1.0/molecule.yml +++ b/roles/server/molecule/2.1.0/molecule.yml @@ -72,7 +72,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy diff --git a/roles/server/molecule/2.2.0/molecule.yml b/roles/server/molecule/2.2.0/molecule.yml index 47f80c03e..8e4540820 100644 --- a/roles/server/molecule/2.2.0/molecule.yml +++ b/roles/server/molecule/2.2.0/molecule.yml @@ -72,7 +72,7 @@ scenario: - prepare - converge # - idempotence # disable for now, as we have non-idempotent tasks - - side_effect + # - side_effect - verify - cleanup - destroy From e426afae8ab66c6d6e16e690c1b395c72b2d9457 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 06:45:32 +0000 Subject: [PATCH 089/117] Bump contributor-assistant/github-action from 2.3.1 to 2.3.2 Bumps [contributor-assistant/github-action](https://github.com/contributor-assistant/github-action) from 2.3.1 to 2.3.2. - [Release notes](https://github.com/contributor-assistant/github-action/releases) - [Commits](https://github.com/contributor-assistant/github-action/compare/v2.3.1...v2.3.2) --- updated-dependencies: - dependency-name: contributor-assistant/github-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/cla.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cla.yaml b/.github/workflows/cla.yaml index fc25f319a..1b195aeb3 100644 --- a/.github/workflows/cla.yaml +++ b/.github/workflows/cla.yaml @@ -18,7 +18,7 @@ jobs: steps: - name: 'CLA Assistant' if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA or my organization already has a signed CLA.') || github.event_name == 'pull_request_target' - uses: contributor-assistant/github-action@v2.3.1 + uses: contributor-assistant/github-action@v2.3.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # the below token should have repo scope and must be manually added by you in the repository's secret From e57d8f8589d86b1dd88b7bbf819035d0e615964b Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Mon, 25 Mar 2024 20:50:00 +0100 Subject: [PATCH 090/117] modify: move and update are exclusive operation --- plugins/modules/host.py | 61 +++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 9d9908d51..68f80d79a 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -28,18 +28,25 @@ required: true type: str folder: - description: The folder your host is located in. On create it defaults to C(/). + description: + - The folder your host is located in. + On create it defaults to C(/). + B(For existing host, host is moved to the specified folder if different + and this procedue is mutualy exclusive with specified + I(attributes), I(update_attributes), and I(remove_attributes)). type: str attributes: description: - The attributes of your host as described in the API documentation. B(Attention! This option OVERWRITES all existing attributes!) + B(Attention! I(folder) should match the folder where host is residing) If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw required: false update_attributes: description: - The update_attributes of your host as described in the API documentation. + B(Attention! I(folder) should match the folder where host is residing) This will only update the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw @@ -47,6 +54,7 @@ remove_attributes: description: - The remove_attributes of your host as described in the API documentation. + B(Attention! I(folder) should match the folder where host is residing) B(If a list of strings is supplied, the listed attributes are removed.) B(If extended_functionality and a dict is supplied, the attributes that exactly match the passed attributes are removed.) @@ -334,13 +342,6 @@ def _detect_changes(self): "attributes: %s" % json.dumps(desired_attributes.get("attributes")) ) - if ( - desired_attributes.get("folder") - and current_folder - and current_folder != desired_attributes.get("folder") - ): - changes.append("folder") - if desired_attributes.get("remove_attributes"): tmp_remove_attributes = desired_attributes.get("remove_attributes") @@ -387,6 +388,21 @@ def _detect_changes(self): exception=e, ) + if ( + desired_attributes.get("folder") + and current_folder + and current_folder != desired_attributes.get("folder") + ): + if self.state == "present" and len(changes) > 0: + self.module.fail_json( + msg="ERROR: The folder parameter is different from the folder in which the host is located, while other parameters are also specified!\n \ + If you want to move the host to a specific folder, please omit the other parameters: \ + 'attributes', 'update_attributes' and 'remove_attributes'". + exception=e, + ) + else: + changes.append("folder") + if self.extended_functionality: self.desired = desired_attributes.copy() @@ -468,34 +484,31 @@ def edit(self): if self.module.check_mode: return self._check_output("edit") - result_move = {} if data.get("folder"): tmp = {} tmp["target_folder"] = data.pop("folder") - result_move = self._fetch( + result = self._fetch( code_mapping=HostHTTPCodes.move, endpoint=self._build_move_endpoint(), data=tmp, method="POST", ) - result_move = result_move._replace( - msg=result_move.msg + ". Moved from to: %s" % tmp.get("target_folder") + return result._replace( + msg=result.msg + ". Moved from to: %s" % tmp.get("target_folder") + ) + else: + result = self._fetch( + code_mapping=HostHTTPCodes.edit, + endpoint=self._build_default_endpoint(), + data=data, + method="PUT", ) - result = self._fetch( - code_mapping=HostHTTPCodes.edit, - endpoint=self._build_default_endpoint(), - data=data, - method="PUT", - ) - - return result._replace( - msg=((result_move.msg + ". ") if result_move != {} else "") - + result.msg - + ". Changed: %s" % ", ".join(self._changed_items) - ) + return result._replace( + msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) + ) def delete(self): if self.module.check_mode: From 5044c03e06b1bcf73cb16639d7b8a5a52ebc65cf Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Mon, 25 Mar 2024 20:51:58 +0100 Subject: [PATCH 091/117] fix: typo --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 68f80d79a..e232d9887 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -397,7 +397,7 @@ def _detect_changes(self): self.module.fail_json( msg="ERROR: The folder parameter is different from the folder in which the host is located, while other parameters are also specified!\n \ If you want to move the host to a specific folder, please omit the other parameters: \ - 'attributes', 'update_attributes' and 'remove_attributes'". + 'attributes', 'update_attributes' and 'remove_attributes'.", exception=e, ) else: From b7caa61fa6f8ec906ab8285d3917ddb08bad7ddd Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 26 Mar 2024 15:50:07 -0400 Subject: [PATCH 092/117] Bugfix changelog. --- changelogs/archive/4.3.0/lookups.yml | 2 +- changelogs/changelog.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/archive/4.3.0/lookups.yml b/changelogs/archive/4.3.0/lookups.yml index 1c8d0172f..f1006663a 100644 --- a/changelogs/archive/4.3.0/lookups.yml +++ b/changelogs/archive/4.3.0/lookups.yml @@ -6,4 +6,4 @@ minor_changes: known_issues: - Lookup modules - When using inventory variables to configure e.g., the server_url, it is not possible to assign other variables to these variables. - This is a limitation of Ansble itself. + This is a limitation of Ansible itself. diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index f4e51c674..cbbe09c18 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -837,7 +837,7 @@ releases: known_issues: - Lookup modules - When using inventory variables to configure e.g., the server_url, it is not possible to assign other variables to these variables. This is a - limitation of Ansble itself. + limitation of Ansible itself. minor_changes: - Folder module - Extend attribute management. Please refer to the module documentation for more details. From 687d90ead2d81bf086aa6551508ca06cb99b912f Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 26 Mar 2024 15:50:37 -0400 Subject: [PATCH 093/117] Bugfix lookup module examples. --- plugins/lookup/README.md | 12 ++++++------ plugins/lookup/bakery.py | 12 ++++++------ plugins/lookup/folder.py | 8 ++++---- plugins/lookup/folders.py | 8 ++++---- plugins/lookup/host.py | 8 ++++---- plugins/lookup/hosts.py | 8 ++++---- plugins/lookup/rule.py | 8 ++++---- plugins/lookup/rules.py | 8 ++++---- plugins/lookup/ruleset.py | 8 ++++---- plugins/lookup/rulesets.py | 8 ++++---- plugins/lookup/version.py | 8 ++++---- roles/server/README.md | 6 +++--- roles/server/defaults/main.yml | 2 +- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/plugins/lookup/README.md b/plugins/lookup/README.md index c5b855619..e711ed070 100644 --- a/plugins/lookup/README.md +++ b/plugins/lookup/README.md @@ -6,8 +6,8 @@ This way, they do not need to be provided at task level. ### Method 1: Environment variables ```bash -export ANSIBLE_LOOKUP_CHECKMK_SERVER_URL="https://myserver" -export ANSIBLE_LOOKUP_CHECKMK_SITE=mysite +export ANSIBLE_LOOKUP_CHECKMK_SERVER_URL="https://my_server" +export ANSIBLE_LOOKUP_CHECKMK_SITE=my_site export ANSIBLE_LOOKUP_AUTOMATION_USER=automation export ANSIBLE_LOOKUP_AUTOMATION_SECRET=mysecret export ANSIBLE_LOOKUP_VALIDATE_CERTS=False @@ -16,8 +16,8 @@ export ANSIBLE_LOOKUP_VALIDATE_CERTS=False ### Method 2: In `ansible.cfg` ```ini [checkmk_lookup] -server_url = https://myserver -site = mysite +server_url = https://my_server +site = my_site automation_user = automation automation_secret = mysecret validate_certs = False @@ -30,8 +30,8 @@ validate_certs = False hosts: localhost gather_facts: false vars: - ansible_lookup_checkmk_server_url: "https://myserver" - ansible_lookup_checkmk_site: "mysite" + ansible_lookup_checkmk_server_url: "https://my_server" + ansible_lookup_checkmk_site: "my_site" ansible_lookup_automation_user: "automation" ansible_lookup_automation_secret: "mysecret" ansible_lookup_validate_certs: false diff --git a/plugins/lookup/bakery.py b/plugins/lookup/bakery.py index 6308bb351..bf56d9c36 100644 --- a/plugins/lookup/bakery.py +++ b/plugins/lookup/bakery.py @@ -89,8 +89,8 @@ msg: "Bakery status is {{ bakery }}" vars: bakery: "{{ lookup('checkmk.general.bakery', - server_url=http://myserver, - site=mysite, + server_url=http://my_server, + site=my_site, validate_certs=False, automation_user=automation_user, automation_secret=automation_secret @@ -100,10 +100,10 @@ ansible.builtin.debug: msg: "Bakery status is {{ bakery }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false bakery: "{{ lookup('checkmk.general.bakery') }}" """ diff --git a/plugins/lookup/folder.py b/plugins/lookup/folder.py index a2b5db1cd..b7c849da4 100644 --- a/plugins/lookup/folder.py +++ b/plugins/lookup/folder.py @@ -107,10 +107,10 @@ ansible.builtin.debug: msg: "Attributes of folder /network: {{ attributes }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.folder', '~tests') }}" """ diff --git a/plugins/lookup/folders.py b/plugins/lookup/folders.py index 4a18d7aaf..aafcee525 100644 --- a/plugins/lookup/folders.py +++ b/plugins/lookup/folders.py @@ -143,10 +143,10 @@ ansible.builtin.debug: msg: "Folder tree: {{ item.id }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ lookup('checkmk.general.folders', diff --git a/plugins/lookup/host.py b/plugins/lookup/host.py index af9a191fc..e395c95d1 100644 --- a/plugins/lookup/host.py +++ b/plugins/lookup/host.py @@ -114,10 +114,10 @@ ansible.builtin.debug: msg: "Attributes of host example: {{ attributes }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.host', 'example.com', effective_attributes=True) }}" """ diff --git a/plugins/lookup/hosts.py b/plugins/lookup/hosts.py index 50756e84a..e1acfd9c6 100644 --- a/plugins/lookup/hosts.py +++ b/plugins/lookup/hosts.py @@ -111,10 +111,10 @@ ansible.builtin.debug: msg: "Host: {{ item.id }} in folder {{ item.extensions.folder }}, IP: {{ item.extensions.effective_attributes.ipaddress }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ lookup('checkmk.general.hosts', effective_attributes=True) }}" diff --git a/plugins/lookup/rule.py b/plugins/lookup/rule.py index 105f39034..95cd0926a 100644 --- a/plugins/lookup/rule.py +++ b/plugins/lookup/rule.py @@ -107,10 +107,10 @@ ansible.builtin.debug: msg: "Rule: {{ extensions }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.rule', rule_id='a9285bc1-dcaf-45e0-a3ba-ad398ef06a49') }}" """ diff --git a/plugins/lookup/rules.py b/plugins/lookup/rules.py index c36349ea7..1395964b8 100644 --- a/plugins/lookup/rules.py +++ b/plugins/lookup/rules.py @@ -136,10 +136,10 @@ ansible.builtin.debug: msg: "Rule: {{ item.extensions }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ lookup('checkmk.general.rules', ruleset='host_groups') }}" diff --git a/plugins/lookup/ruleset.py b/plugins/lookup/ruleset.py index 790fd7db9..47f358bf9 100644 --- a/plugins/lookup/ruleset.py +++ b/plugins/lookup/ruleset.py @@ -107,10 +107,10 @@ ansible.builtin.debug: msg: "Ruleset: {{ extensions }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false extensions: "{{ lookup('checkmk.general.ruleset', ruleset='host_groups') }}" """ diff --git a/plugins/lookup/rulesets.py b/plugins/lookup/rulesets.py index 10acc985d..6594360b5 100644 --- a/plugins/lookup/rulesets.py +++ b/plugins/lookup/rulesets.py @@ -146,10 +146,10 @@ ansible.builtin.debug: msg: "Ruleset {{ item.extension.name }} is deprecated." vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ lookup('checkmk.general.rulesets', regex='', rulesets_deprecated=True, rulesets_used=True) }}" diff --git a/plugins/lookup/version.py b/plugins/lookup/version.py index a6949ef22..294df07be 100644 --- a/plugins/lookup/version.py +++ b/plugins/lookup/version.py @@ -100,10 +100,10 @@ ansible.builtin.debug: msg: "Server version is {{ version }}" vars: - ansible_lookup_checkmk_server_url: "{{ checkmk_var_server_url }}" - ansible_lookup_checkmk_site: "{{ outer_item.site }}" - ansible_lookup_checkmk_automation_user: "{{ checkmk_var_automation_user }}" - ansible_lookup_checkmk_automation_secret: "{{ checkmk_var_automation_secret }}" + ansible_lookup_checkmk_server_url: "http://my_server/" + ansible_lookup_checkmk_site: "my_site" + ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.version') }}" """ diff --git a/roles/server/README.md b/roles/server/README.md index f4e69f6aa..864eda075 100644 --- a/roles/server/README.md +++ b/roles/server/README.md @@ -42,7 +42,7 @@ The edition you want to use. Valid values are `cre`, `cfe`, `cee`, `cce` and `cm For details about the editions see: https://checkmk.com/product/editions -Note, that you need credentials, to download the following editions: `cee` and `cme`. +Note, that you need credentials, to download the following editions: `cee` and `cme`. See below variables, to set those. checkmk_server_download_user: [] @@ -73,7 +73,7 @@ Whether to allow downgrading a site's version. Note: this is not a recommended procedure, and will not be supported for enterprise customers. checkmk_server_sites: - - name: mysite + - name: my_site version: "{{ checkmk_server_version }}" update_conflict_resolution: abort state: started @@ -99,7 +99,7 @@ Valid choices include `install`, `keepold` and `abort`. Site configuration can be passed with the `omd_config` keyword. The format can be seen above, for a list of variables run `omd show` -on an existing site. +on an existing site. **Pay special attention to the `omd_auto_restart` variable!** As site configuration needs the site to be stopped, this needs to be handled. By default the variable is set to `false` to avoid unexpected restarting. However, no configuration will be performed if the site is started. checkmk_server_backup_on_update: 'true' diff --git a/roles/server/defaults/main.yml b/roles/server/defaults/main.yml index a7a084093..b9b7c2edd 100644 --- a/roles/server/defaults/main.yml +++ b/roles/server/defaults/main.yml @@ -32,7 +32,7 @@ checkmk_server_download_user: [] checkmk_server_download_pass: [] checkmk_server_sites: [] -# - name: mysite +# - name: my_site # version: "{{ checkmk_server_version }}" # state: started # admin_pw: "{{ automation_secret | default(omit) }}" From aa17309dd4553a38ff02da0011d5f6700488554e Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 26 Mar 2024 17:53:52 -0400 Subject: [PATCH 094/117] Add changelogs. --- changelogs/fragments/folder.yml | 3 +++ changelogs/fragments/host.yml | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/folder.yml create mode 100644 changelogs/fragments/host.yml diff --git a/changelogs/fragments/folder.yml b/changelogs/fragments/folder.yml new file mode 100644 index 000000000..66af9719d --- /dev/null +++ b/changelogs/fragments/folder.yml @@ -0,0 +1,3 @@ +bugfixes: + - Folder module - Fix issues with uppercase and lowercase names. + - Folder module - Fix issue where the `name` (alias `title`) was entirely ignored. diff --git a/changelogs/fragments/host.yml b/changelogs/fragments/host.yml new file mode 100644 index 000000000..358aaa913 --- /dev/null +++ b/changelogs/fragments/host.yml @@ -0,0 +1,6 @@ +major_changes: + - Host module - Enable check mode. + - Host module - Update attribute management behavior. Refer to the documentation for details. + +minor_changes: + - Host module - Migrate module to the new collection API. From 4652fb6b21f61c2fd99c63bdab4c8638386f3ad8 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 26 Mar 2024 17:54:02 -0400 Subject: [PATCH 095/117] Fix documentation. --- plugins/modules/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e232d9887..3039b9277 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -56,11 +56,11 @@ - The remove_attributes of your host as described in the API documentation. B(Attention! I(folder) should match the folder where host is residing) B(If a list of strings is supplied, the listed attributes are removed.) - B(If extended_functionality and a dict is supplied, the attributes that exactly match + B(If) I(extended_functionality) B(and a dict is supplied, the attributes that exactly match the passed attributes are removed.) This will only remove the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). - As of Check MK v2.2.0p7 and v2.3.0b1, simultaneous use of I(attributes), + As of Checkmk 2.2.0p7 and 2.3.0b1, simultaneous use of I(attributes), I(remove_attributes), and I(update_attributes) is no longer supported. type: raw required: false From 14d887c3bcfed220be343d08c9910436d12005c7 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Wed, 27 Mar 2024 14:25:50 -0400 Subject: [PATCH 096/117] Fix typo in EXAMPLES. --- plugins/lookup/bakery.py | 2 +- plugins/lookup/folder.py | 2 +- plugins/lookup/folders.py | 2 +- plugins/lookup/host.py | 2 +- plugins/lookup/hosts.py | 2 +- plugins/lookup/rule.py | 2 +- plugins/lookup/rules.py | 2 +- plugins/lookup/ruleset.py | 2 +- plugins/lookup/rulesets.py | 2 +- plugins/lookup/version.py | 2 +- plugins/modules/bakery.py | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/lookup/bakery.py b/plugins/lookup/bakery.py index bf56d9c36..79bb05b6b 100644 --- a/plugins/lookup/bakery.py +++ b/plugins/lookup/bakery.py @@ -102,7 +102,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false bakery: "{{ lookup('checkmk.general.bakery') }}" diff --git a/plugins/lookup/folder.py b/plugins/lookup/folder.py index b7c849da4..4f6864f49 100644 --- a/plugins/lookup/folder.py +++ b/plugins/lookup/folder.py @@ -109,7 +109,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.folder', '~tests') }}" diff --git a/plugins/lookup/folders.py b/plugins/lookup/folders.py index aafcee525..cfd6dcfa0 100644 --- a/plugins/lookup/folders.py +++ b/plugins/lookup/folders.py @@ -145,7 +145,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ diff --git a/plugins/lookup/host.py b/plugins/lookup/host.py index e395c95d1..8ade9d595 100644 --- a/plugins/lookup/host.py +++ b/plugins/lookup/host.py @@ -116,7 +116,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.host', 'example.com', effective_attributes=True) }}" diff --git a/plugins/lookup/hosts.py b/plugins/lookup/hosts.py index e1acfd9c6..50cbf2fff 100644 --- a/plugins/lookup/hosts.py +++ b/plugins/lookup/hosts.py @@ -113,7 +113,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ diff --git a/plugins/lookup/rule.py b/plugins/lookup/rule.py index 95cd0926a..053b80682 100644 --- a/plugins/lookup/rule.py +++ b/plugins/lookup/rule.py @@ -109,7 +109,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.rule', rule_id='a9285bc1-dcaf-45e0-a3ba-ad398ef06a49') }}" diff --git a/plugins/lookup/rules.py b/plugins/lookup/rules.py index 1395964b8..498379ffe 100644 --- a/plugins/lookup/rules.py +++ b/plugins/lookup/rules.py @@ -138,7 +138,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ diff --git a/plugins/lookup/ruleset.py b/plugins/lookup/ruleset.py index 47f358bf9..fc54ddeff 100644 --- a/plugins/lookup/ruleset.py +++ b/plugins/lookup/ruleset.py @@ -109,7 +109,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false extensions: "{{ lookup('checkmk.general.ruleset', ruleset='host_groups') }}" diff --git a/plugins/lookup/rulesets.py b/plugins/lookup/rulesets.py index 6594360b5..c95ef5da8 100644 --- a/plugins/lookup/rulesets.py +++ b/plugins/lookup/rulesets.py @@ -148,7 +148,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false loop: "{{ diff --git a/plugins/lookup/version.py b/plugins/lookup/version.py index 294df07be..f869f1889 100644 --- a/plugins/lookup/version.py +++ b/plugins/lookup/version.py @@ -102,7 +102,7 @@ vars: ansible_lookup_checkmk_server_url: "http://my_server/" ansible_lookup_checkmk_site: "my_site" - ansible_lookup_checkmk_automation_user: "my_user + ansible_lookup_checkmk_automation_user: "my_user" ansible_lookup_checkmk_automation_secret: "my_secret" ansible_lookup_checkmk_validate_certs: false attributes: "{{ lookup('checkmk.general.version') }}" diff --git a/plugins/modules/bakery.py b/plugins/modules/bakery.py index 35b9a4d28..07badc2c6 100644 --- a/plugins/modules/bakery.py +++ b/plugins/modules/bakery.py @@ -60,7 +60,7 @@ automation_user: "my_user" automation_secret: "my_secret" signature_key_id: 1 - signature_key_passphrase: "secretkey" + signature_key_passphrase: "my_key" state: "signed" # Bake and sign all agents. - name: "Bake and sign all agents." @@ -70,7 +70,7 @@ automation_user: "my_user" automation_secret: "my_secret" signature_key_id: 1 - signature_key_passphrase: "secretkey" + signature_key_passphrase: "my_key" state: "baked_signed" """ From 2761982184370ec890cb86da189feb1889143254 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:11:18 +0100 Subject: [PATCH 097/117] update: --- plugins/modules/host.py | 158 ++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 63 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 20ff06d93..2bce39f87 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -28,18 +28,25 @@ required: true type: str folder: - description: The folder your host is located in. On create it defaults to C(/). + description: + - The folder your host is located in. + On create it defaults to C(/). + B(For existing host, host is moved to the specified folder if different + and this procedue is mutualy exclusive with specified + I(attributes), I(update_attributes), and I(remove_attributes)). type: str attributes: description: - The attributes of your host as described in the API documentation. B(Attention! This option OVERWRITES all existing attributes!) + B(Attention! I(folder) should match the folder where host is residing) If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw required: false update_attributes: description: - The update_attributes of your host as described in the API documentation. + B(Attention! I(folder) should match the folder where host is residing) This will only update the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). type: raw @@ -47,12 +54,13 @@ remove_attributes: description: - The remove_attributes of your host as described in the API documentation. + B(Attention! I(folder) should match the folder where host is residing) B(If a list of strings is supplied, the listed attributes are removed.) - B(If extended_functionality and a dict is supplied, the attributes that exactly match + B(If) I(extended_functionality) B(and a dict is supplied, the attributes that exactly match the passed attributes are removed.) This will only remove the given attributes. If you are using custom tags, make sure to prepend the attribute with C(tag_). - As of Check MK v2.2.0p7 and v2.3.0b1, simultaneous use of I(attributes), + As of Checkmk 2.2.0p7 and 2.3.0b1, simultaneous use of I(attributes), I(remove_attributes), and I(update_attributes) is no longer supported. type: raw required: false @@ -413,7 +421,7 @@ def _detect_changes_rename(self): if desired_name and current_name != desired_name: changes.append("rename") else: - self.desired.pop("new_name", "") + self.desired.pop("new_name", None) return changes @@ -453,12 +461,6 @@ def _detect_changes_nodes(self): return changes def _detect_changes_attributes(self): - ATTRIBUTE_FILEDS = [ - "attributes", - "update_attributes", - "remove_attributes", - ] - current_attributes = self.current.get("attributes", {}) desired_attributes = self.desired.copy() changes = [] @@ -467,11 +469,7 @@ def _detect_changes_attributes(self): "attributes" ) and current_attributes != desired_attributes.get("attributes"): changes.append( - "attributes: %s %s" - % ( - json.dumps(current_attributes), - json.dumps(desired_attributes.get("attributes")), - ) + "attributes: %s" % json.dumps(desired_attributes.get("attributes")) ) if desired_attributes.get("update_attributes"): @@ -534,7 +532,7 @@ def _detect_changes_attributes(self): ) if self.extended_functionality: - for key in ATTRIBUTE_FILEDS: + for key in HOST: if desired_attributes.get(key): self.desired[key] = desired_attributes.get(key) else: @@ -543,19 +541,27 @@ def _detect_changes_attributes(self): return changes def _detect_changes(self): - changes = [] - - loc_functions = [ - self._detect_changes_folder, - self._detect_changes_attributes, - self._detect_changes_nodes, - self._detect_changes_rename, - ] - - for fun in loc_functions: - changes += fun() + loc_functions = { + "folder": self._detect_changes_folder, + "attributes": self._detect_changes_attributes, + "nodes": self._detect_changes_nodes, + "name": self._detect_changes_rename, + } + + changes_dict = {key: fun() for key, fun in loc_functions.items()} + + if (self.state == "present" + and len(changes_dict.get("folder")) > 0 + and len(changes_dict.get("attributes")) > 0 + ): + self.module.fail_json( + msg="ERROR: The folder parameter is different from the folder in which the host is located, while other parameters are also specified!\n \ + If you want to move the host to a specific folder, please omit the other parameters: \ + 'attributes', 'update_attributes' and 'remove_attributes'.", + exception=e, + ) - return changes + return list(sum(changes_dict.values(), []) def _get_current(self): result = self._fetch( @@ -600,6 +606,19 @@ def _check_output(self, mode): def needs_update(self): return len(self._changed_items) > 0 + # adapted from Lars Getwan's rule module + def _merge_results(self, results): + return RESULT( + http_code=results[-1].http_code, + msg=", ".join( + ["%s (%d)" % (r.msg, r.http_code) for r in results] + ), + content=results[-1].content, + etag=results[-1].etag, + failed=any(r.failed for r in results), + changed=any(r.changed for r in results), + ) + def create(self): data = self.desired.copy() if data.get("attributes", {}) == {}: @@ -715,30 +734,44 @@ def _edit_nodes(self): return result def _edit_attributes(self): - data = self.desired.copy() - # data.pop("host_name") - CLEAN_FIELDS = [ - "host_name", - "folder", - "nodes", - "new_name", - ] + result = RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) - for key in CLEAN_FIELDS: - data.pop(key, None) + if (self.desired.get("attributes") + or self.desired.get("update_attributes") + or self.desired.get("remove_attributes") + ): + data = self.desired.copy() + CLEAN_FIELDS = [ + "host_name", + "folder", + "nodes", + "new_name", + ] - result = self._fetch( - code_mapping=( - HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit - ), - endpoint=self._build_default_endpoint(), - data=data, - method="PUT", - ) + for key in CLEAN_FIELDS: + data.pop(key, None) - return result._replace( - msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) - ) + result = self._fetch( + code_mapping=( + HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit + ), + endpoint=self._build_default_endpoint(), + data=data, + method="PUT", + ) + + result = result._replace( + msg=result.msg + ". Changed: %s" % ", ".join(self._changed_items) + ) + + return result def edit(self): self.headers["if-Match"] = self.etag @@ -746,13 +779,16 @@ def edit(self): if self.module.check_mode: return self._check_output("edit") - result = RESULT( - http_code=0, - msg="", - content="", - etag="", - failed=False, - changed=False, + results = [] + results.append( + RESULT( + http_code=0, + msg="", + content="", + etag="", + failed=False, + changed=False, + ) ) loc_functions = [ @@ -766,14 +802,10 @@ def edit(self): for fun in loc_functions: result_loc = fun() - result = result._replace( - msg=result.msg - + (". " if result_loc.msg != "" else "") - + result_loc.msg, - changed=result.changed | result_loc.changed, - ) + if result_loc.msg != "": + results.append(result_loc.copy()) - return result + return self._merge_results(results) def delete(self): if self.module.check_mode: From c961c295bb545eec31bc748474c12e2ae9766287 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:13:56 +0100 Subject: [PATCH 098/117] fix: typo --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 2bce39f87..e93d74686 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -561,7 +561,7 @@ def _detect_changes(self): exception=e, ) - return list(sum(changes_dict.values(), []) + return list(sum(changes_dict.values(), [])) def _get_current(self): result = self._fetch( From 4be126089102b75b5d5742b228336f6a616a79dd Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:16:43 +0100 Subject: [PATCH 099/117] fix: linting --- plugins/modules/host.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index e93d74686..f67633b85 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -550,7 +550,8 @@ def _detect_changes(self): changes_dict = {key: fun() for key, fun in loc_functions.items()} - if (self.state == "present" + if ( + self.state == "present" and len(changes_dict.get("folder")) > 0 and len(changes_dict.get("attributes")) > 0 ): @@ -610,9 +611,7 @@ def needs_update(self): def _merge_results(self, results): return RESULT( http_code=results[-1].http_code, - msg=", ".join( - ["%s (%d)" % (r.msg, r.http_code) for r in results] - ), + msg=", ".join(["%s (%d)" % (r.msg, r.http_code) for r in results]), content=results[-1].content, etag=results[-1].etag, failed=any(r.failed for r in results), @@ -743,7 +742,8 @@ def _edit_attributes(self): changed=False, ) - if (self.desired.get("attributes") + if ( + self.desired.get("attributes") or self.desired.get("update_attributes") or self.desired.get("remove_attributes") ): @@ -760,7 +760,9 @@ def _edit_attributes(self): result = self._fetch( code_mapping=( - HostHTTPCodes.edit_cluster if self.is_cluster else HostHTTPCodes.edit + HostHTTPCodes.edit_cluster + if self.is_cluster else + HostHTTPCodes.edit ), endpoint=self._build_default_endpoint(), data=data, From aee961eec1dffd0ddc014e45f7f6fa8f55709070 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:20:11 +0100 Subject: [PATCH 100/117] fix: bug --- plugins/modules/host.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index f67633b85..39bfc8845 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -559,7 +559,6 @@ def _detect_changes(self): msg="ERROR: The folder parameter is different from the folder in which the host is located, while other parameters are also specified!\n \ If you want to move the host to a specific folder, please omit the other parameters: \ 'attributes', 'update_attributes' and 'remove_attributes'.", - exception=e, ) return list(sum(changes_dict.values(), [])) @@ -761,8 +760,8 @@ def _edit_attributes(self): result = self._fetch( code_mapping=( HostHTTPCodes.edit_cluster - if self.is_cluster else - HostHTTPCodes.edit + if self.is_cluster + else HostHTTPCodes.edit ), endpoint=self._build_default_endpoint(), data=data, From a656f1185ae9f536b6b48f726d807a614923a6c8 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:41:36 +0100 Subject: [PATCH 101/117] fix: cluster to host --- tests/integration/targets/host/tasks/test.yml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/integration/targets/host/tasks/test.yml b/tests/integration/targets/host/tasks/test.yml index 8c6e8ce0c..b89783bd6 100644 --- a/tests/integration/targets/host/tasks/test.yml +++ b/tests/integration/targets/host/tasks/test.yml @@ -182,7 +182,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -211,7 +211,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency of create cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -228,7 +228,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Modify nodes in cluster host." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -259,7 +259,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency, Modify nodes in cluster host." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -278,7 +278,7 @@ second: "{{ checkmk_cluster_hosts[1] }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Add nodes to cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -307,7 +307,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency of Add nodes to cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -336,7 +336,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Remove nodes to cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -365,7 +365,7 @@ run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Cehck idempotency of Remove nodes to cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -433,7 +433,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create cluster host with update_attributes without folder." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -452,7 +452,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency on update_attributes for only a subset of attributes." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -469,7 +469,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Remove Attributes of cluster host." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -484,7 +484,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Check idempotency on remove_attributes." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" @@ -499,7 +499,7 @@ loop: "{{ checkmk_cluster_hosts }}" - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete cluster hosts." - cluster: + host: server_url: "{{ checkmk_var_server_url }}" site: "{{ outer_item.site }}" automation_user: "{{ checkmk_var_automation_user }}" From fb89e704a418f78cba293c839161912714ad0b52 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 01:47:56 +0100 Subject: [PATCH 102/117] fix: error --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 39bfc8845..67227f33b 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -804,7 +804,7 @@ def edit(self): result_loc = fun() if result_loc.msg != "": - results.append(result_loc.copy()) + results.append(result_loc) return self._merge_results(results) From ddb00dd078a8b0e30b25de586cb036337afa8f0f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 02:22:03 +0100 Subject: [PATCH 103/117] fix: update node management --- plugins/modules/host.py | 54 ++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 67227f33b..0c6bdea61 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -80,6 +80,7 @@ nodes: description: - Nodes, members of the cluster-container host provided in name. + B(Mutualy exclusive with I(add_nodes) and I(remove_nodes).) required: false type: list elements: str @@ -87,14 +88,14 @@ description: - List of nodes to be added as members of the cluster-container host provided in name. Works only if the existing host was already a cluster host, or entirely new is created. - B(Mutualy exclusive with nodes.) + B(Mutualy exclusive with I(nodes) and I(remove_nodes).) required: false type: list elements: str remove_nodes: description: - List of nodes to be removes from the cluster-container host provided in name. - B(Mutualy exclusive with nodes.) + B(Mutualy exclusive with I(nodes) and I(add_nodes).) required: false type: list elements: str @@ -305,15 +306,6 @@ def __init__(self, module): if self.params.get("new_name"): self.desired["new_name"] = self.params.get("new_name") - if self.params.get("nodes"): - self.desired["nodes"] = self.params.get("nodes") - - if self.params.get("add_nodes"): - self.desired["add_nodes"] = self.params.get("add_nodes") - - if self.params.get("remove_nodes"): - self.desired["remove_nodes"] = self.params.get("remove_nodes") - for key in HOST: if self.params.get(key): self.desired[key] = self.params.get(key) @@ -335,6 +327,23 @@ def __init__(self, module): ): self.desired["folder"] = self.params["folder"] + if self.params.get("nodes"): + self.desired["nodes"] = self.params.get("nodes") + + if self.params.get("add_nodes"): + if self.desired.get("nodes"): + self.desired["nodes"] += [el for el in self.params.get("add_nodes") if el not in self.desired["nodes"]] + elif self.current.get("cluster_nodes"): + self.desired["nodes"] += self.current.get("cluster_nodes") + [el for el in self.params.get("add_nodes") if el not in self.current.get("cluster_nodes")] + else: + self.desired["nodes"] = self.desired.get("add_nodes") + + if self.params.get("remove_nodes"): + if self.desired.get("nodes"): + self.desired["nodes"] = [el for el in self.desired["nodes"] if el not in self.params.get("remove_nodes")] + elif self.current.get("cluster_nodes"): + self.desired["nodes"] = [el for el in self.current.get("cluster_nodes") if el not in self.params.get("remove_nodes")] + self._changed_items = self._detect_changes() self._verify_compatibility() @@ -433,30 +442,14 @@ def _detect_changes_nodes(self): if self.current.get("cluster_nodes"): current_nodes = self.current.get("cluster_nodes") - if ( - desired_parameters.get("nodes") - or desired_parameters.get("add_nodes") - or desired_parameters.get("remove_nodes") - ): - desired_nodes = desired_parameters.get("nodes", []) - - desired_nodes = desired_nodes + desired_parameters.get("add_nodes", []) - - desired_nodes = [ - el - for el in desired_nodes - if el not in desired_parameters.get("remove_nodes", []) - ] - + if desired_parameters.get("nodes"): if ( - len([el for el in current_nodes if el not in desired_nodes]) > 0 - or len([el for el in desired_nodes if el not in current_nodes]) > 0 + len([el for el in current_nodes if el not in desired_parameters.get("nodes")]) > 0 + or len([el for el in desired_parameters.get("nodes") if el not in current_nodes]) > 0 ): changes.append("nodes") else: self.desired.pop("nodes", None) - self.desired.pop("add_nodes", None) - self.desired.pop("remove_nodes", None) return changes @@ -850,6 +843,7 @@ def run_module(): mutually_exclusive=[ ("nodes", "add_nodes"), ("nodes", "remove_nodes"), + ("add_nodes", "remove_nodes"), ], supports_check_mode=True, ) From 9f40bc321799144258586630ea33f8e26ec4bb7b Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 02:31:29 +0100 Subject: [PATCH 104/117] fix: bug and linting --- plugins/modules/host.py | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 0c6bdea61..976cafecf 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -332,17 +332,33 @@ def __init__(self, module): if self.params.get("add_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] += [el for el in self.params.get("add_nodes") if el not in self.desired["nodes"]] + self.desired["nodes"] += [ + el + for el in self.params.get("add_nodes") + if el not in self.desired["nodes"] + ] elif self.current.get("cluster_nodes"): - self.desired["nodes"] += self.current.get("cluster_nodes") + [el for el in self.params.get("add_nodes") if el not in self.current.get("cluster_nodes")] + self.desired["nodes"] = self.current.get("cluster_nodes") + [ + el + for el in self.params.get("add_nodes") + if el not in self.current.get("cluster_nodes") + ] else: self.desired["nodes"] = self.desired.get("add_nodes") if self.params.get("remove_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] = [el for el in self.desired["nodes"] if el not in self.params.get("remove_nodes")] + self.desired["nodes"] = [ + el + for el in self.desired["nodes"] + if el not in self.params.get("remove_nodes") + ] elif self.current.get("cluster_nodes"): - self.desired["nodes"] = [el for el in self.current.get("cluster_nodes") if el not in self.params.get("remove_nodes")] + self.desired["nodes"] = [ + el + for el in self.current.get("cluster_nodes") + if el not in self.params.get("remove_nodes") + ] self._changed_items = self._detect_changes() @@ -444,8 +460,20 @@ def _detect_changes_nodes(self): if desired_parameters.get("nodes"): if ( - len([el for el in current_nodes if el not in desired_parameters.get("nodes")]) > 0 - or len([el for el in desired_parameters.get("nodes") if el not in current_nodes]) > 0 + len( + [el + for el in current_nodes + if el not in desired_parameters.get("nodes") + ] + ) + > 0 + or len( + [el + for el in desired_parameters.get("nodes") + if el not in current_nodes + ] + ) + > 0 ): changes.append("nodes") else: From 8e4886ddb6ec0fefb62aec409dd5f40900e4c378 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 02:37:14 +0100 Subject: [PATCH 105/117] fix: linting --- plugins/modules/host.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 976cafecf..27f9a5e7c 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -461,14 +461,16 @@ def _detect_changes_nodes(self): if desired_parameters.get("nodes"): if ( len( - [el + [ + el for el in current_nodes if el not in desired_parameters.get("nodes") ] ) > 0 or len( - [el + [ + el for el in desired_parameters.get("nodes") if el not in current_nodes ] From bec901b5d55771ca4eff73730532fe2665d793e4 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 02:37:59 +0100 Subject: [PATCH 106/117] fix: typo --- tests/integration/targets/host/tasks/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/host/tasks/test.yml b/tests/integration/targets/host/tasks/test.yml index b89783bd6..1bf6ec525 100644 --- a/tests/integration/targets/host/tasks/test.yml +++ b/tests/integration/targets/host/tasks/test.yml @@ -343,7 +343,7 @@ automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" folder: "{{ item.folder }}" - rmove_nodes: "{{ item.remove_nodes }}" + remove_nodes: "{{ item.remove_nodes }}" attributes: site: "{{ outer_item.site }}" ipaddress: 127.0.0.1 From 9252ea0e7563bc12cfcc57648a4f9938448aec4f Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Thu, 28 Mar 2024 02:49:35 +0100 Subject: [PATCH 107/117] fix: linting --- plugins/modules/host.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 27f9a5e7c..cabb1863f 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -462,17 +462,17 @@ def _detect_changes_nodes(self): if ( len( [ - el - for el in current_nodes - if el not in desired_parameters.get("nodes") + el + for el in current_nodes + if el not in desired_parameters.get("nodes") ] ) > 0 or len( [ - el - for el in desired_parameters.get("nodes") - if el not in current_nodes + el + for el in desired_parameters.get("nodes") + if el not in current_nodes ] ) > 0 From 52d0a046194b65a42c7c9599db4123fac847369f Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Fri, 5 Apr 2024 14:04:46 -0400 Subject: [PATCH 108/117] Add changelog. --- changelogs/fragments/host.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/changelogs/fragments/host.yml b/changelogs/fragments/host.yml index 358aaa913..54913c482 100644 --- a/changelogs/fragments/host.yml +++ b/changelogs/fragments/host.yml @@ -1,5 +1,6 @@ major_changes: - Host module - Enable check mode. + - Host module - Add support for cluster hosts. - Host module - Update attribute management behavior. Refer to the documentation for details. minor_changes: From fbab1baf3319476e17b5e88c263c1122eb28d1ce Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 9 Apr 2024 20:17:19 +0200 Subject: [PATCH 109/117] refactor: according to @lgetwan comments --- plugins/modules/host.py | 43 +++++------------------------------------ 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index cabb1863f..dd73aeab8 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -332,33 +332,17 @@ def __init__(self, module): if self.params.get("add_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] += [ - el - for el in self.params.get("add_nodes") - if el not in self.desired["nodes"] - ] + self.desired["nodes"] = list(set(self.desired["nodes"] + self.params.get("add_nodes"))) elif self.current.get("cluster_nodes"): - self.desired["nodes"] = self.current.get("cluster_nodes") + [ - el - for el in self.params.get("add_nodes") - if el not in self.current.get("cluster_nodes") - ] + self.desired["nodes"] = list(set(self.current.get("cluster_nodes") + self.params.get("add_nodes")) else: self.desired["nodes"] = self.desired.get("add_nodes") if self.params.get("remove_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] = [ - el - for el in self.desired["nodes"] - if el not in self.params.get("remove_nodes") - ] + self.desired["nodes"] = list(set(self.desired.get("nodes")) - set(self.params.get("remove_nodes"))) elif self.current.get("cluster_nodes"): - self.desired["nodes"] = [ - el - for el in self.current.get("cluster_nodes") - if el not in self.params.get("remove_nodes") - ] + self.desired["nodes"] = list(set(self.current.get("cluster_nodes")) - set(self.params.get("remove_nodes"))) self._changed_items = self._detect_changes() @@ -459,24 +443,7 @@ def _detect_changes_nodes(self): current_nodes = self.current.get("cluster_nodes") if desired_parameters.get("nodes"): - if ( - len( - [ - el - for el in current_nodes - if el not in desired_parameters.get("nodes") - ] - ) - > 0 - or len( - [ - el - for el in desired_parameters.get("nodes") - if el not in current_nodes - ] - ) - > 0 - ): + if set(current_nodes).symetric_difference(desired_parameters.get("nodes")): changes.append("nodes") else: self.desired.pop("nodes", None) From 1bf7b13eface9f71c3c8da2eed6766b6ceac39e0 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 9 Apr 2024 20:18:50 +0200 Subject: [PATCH 110/117] fix: typo --- plugins/modules/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index dd73aeab8..2eeda9e03 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -334,7 +334,7 @@ def __init__(self, module): if self.desired.get("nodes"): self.desired["nodes"] = list(set(self.desired["nodes"] + self.params.get("add_nodes"))) elif self.current.get("cluster_nodes"): - self.desired["nodes"] = list(set(self.current.get("cluster_nodes") + self.params.get("add_nodes")) + self.desired["nodes"] = list(set(self.current.get("cluster_nodes") + self.params.get("add_nodes"))) else: self.desired["nodes"] = self.desired.get("add_nodes") From d576ef8e87a0db04a2600655d565ed3efacb4f51 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Tue, 9 Apr 2024 20:25:26 +0200 Subject: [PATCH 111/117] fix: typo and linting issues --- plugins/modules/host.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 2eeda9e03..a29f94b30 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -332,17 +332,29 @@ def __init__(self, module): if self.params.get("add_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] = list(set(self.desired["nodes"] + self.params.get("add_nodes"))) + self.desired["nodes"] = list( + set(self.desired["nodes"] + self.params.get("add_nodes")) + ) elif self.current.get("cluster_nodes"): - self.desired["nodes"] = list(set(self.current.get("cluster_nodes") + self.params.get("add_nodes"))) + self.desired["nodes"] = list( + set( + self.current.get("cluster_nodes") + self.params.get("add_nodes") + ) + ) else: self.desired["nodes"] = self.desired.get("add_nodes") if self.params.get("remove_nodes"): if self.desired.get("nodes"): - self.desired["nodes"] = list(set(self.desired.get("nodes")) - set(self.params.get("remove_nodes"))) + self.desired["nodes"] = list( + set(self.desired.get("nodes")) + - set(self.params.get("remove_nodes")) + ) elif self.current.get("cluster_nodes"): - self.desired["nodes"] = list(set(self.current.get("cluster_nodes")) - set(self.params.get("remove_nodes"))) + self.desired["nodes"] = list( + set(self.current.get("cluster_nodes")) + - set(self.params.get("remove_nodes")) + ) self._changed_items = self._detect_changes() @@ -443,7 +455,7 @@ def _detect_changes_nodes(self): current_nodes = self.current.get("cluster_nodes") if desired_parameters.get("nodes"): - if set(current_nodes).symetric_difference(desired_parameters.get("nodes")): + if set(current_nodes).symmetric_difference(desired_parameters.get("nodes")): changes.append("nodes") else: self.desired.pop("nodes", None) From 948bfa23c32b1459086e4cf14554ee40f1e1fcc6 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 10 Apr 2024 14:21:00 +0200 Subject: [PATCH 112/117] Fix failing integration test due to wrong key passphrase. The used passphrase didn't match the one in the injected file, so I changed the file. --- changelogs/fragments/bakery.yml | 2 + .../bakery/files/agent_signature_keys.mk | 131 +++++++----------- 2 files changed, 49 insertions(+), 84 deletions(-) create mode 100644 changelogs/fragments/bakery.yml diff --git a/changelogs/fragments/bakery.yml b/changelogs/fragments/bakery.yml new file mode 100644 index 000000000..3e548f49f --- /dev/null +++ b/changelogs/fragments/bakery.yml @@ -0,0 +1,2 @@ +bugfixes: + - Bakery module - Fix failing integration test due to wrong key passphrase. diff --git a/tests/integration/targets/bakery/files/agent_signature_keys.mk b/tests/integration/targets/bakery/files/agent_signature_keys.mk index 61c2b3eb2..65c25611d 100644 --- a/tests/integration/targets/bakery/files/agent_signature_keys.mk +++ b/tests/integration/targets/bakery/files/agent_signature_keys.mk @@ -2,90 +2,53 @@ agent_signature_keys.update({1: {'alias': 'ansible_collection', 'certificate': '-----BEGIN CERTIFICATE-----\n' - 'MIIFZzCCA0+gAwIBAgIUZgnYcA4yerR7bDBuB6+3RXCK4dEwDQYJKoZIhvcNAQEN\n' - 'BQAwTTEbMBkGA1UEAwwSYW5zaWJsZV9jb2xsZWN0aW9uMRswGQYDVQQKDBJDaGVj\n' - 'a21rIFNpdGUgbG9jYWwxETAPBgNVBAsMCGNta2FkbWluMB4XDTIzMDgxNDExNDgw\n' - 'NloXDTI1MDgxNDExNDgwNlowTTEbMBkGA1UEAwwSYW5zaWJsZV9jb2xsZWN0aW9u\n' - 'MRswGQYDVQQKDBJDaGVja21rIFNpdGUgbG9jYWwxETAPBgNVBAsMCGNta2FkbWlu\n' - 'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwN+Jo6Ia6iJ26yRFlgGb\n' - 'GrodmwGitV+SjQt0qo92AwRdKh4Ws7hmSmN352ZvEzcsEJaTG4yVCTsfwcg3DGgf\n' - 'Iiu/Zc/7vniqrifdS/Z+VYDSb6kaC0vAft91CijyxnQvzbh7htbz+zVxxd6SUd2V\n' - 'xkhn5fYe3ynbyRQZciFa0fZu+Jpg6oKw1Oz/oymhnAiAFmSiXsdEP9HruHtyAOqF\n' - 'j2qcPneIW5xfGp+Fx/flK2F/Ntk6TTkjViC+dun+d9BzdAofxGW8mSjdD/upyE9Y\n' - 'lrjqmQfenRQLFPs+qZYf7uZeEu6ilrxesv/KY1tct1tSKKn198fR3X4vbRbJG6cL\n' - 'tz39Q6VzjoerHuZLEsioJYj+2msgjvIcsWur/MeIgeGVx6ZPpw47JbcJbWRzgnGc\n' - 'RYcUW85mHInNU8YechZqI3TzqXS6gClTwPvGWVh66XRR4c2AxA4wpKJFfKbvMNdH\n' - 'MM02RqDOXO8OAUm4p1TZ3YUP24BZCJ8gVRzK8sgjY2CMWv6O+uiBMDrWWm7CSc33\n' - 'BETxFzqDToJrnYU8IBp8+bOL7AJF5eEs0p9ofLVANHfLXL6BbeS+6W/NzzhkIt2d\n' - 'DLTdgbQnWm6K/BfCZ6n9nxpBGENzzdvB/4x8637KyQL06rZ7z7UiJS6vXZgdbSGY\n' - 'FyxFBkRtDyid8Zvf7ImcSlcCAwEAAaM/MD0wDAYDVR0TAQH/BAIwADAdBgNVHQ4E\n' - 'FgQUUaeTaQ7D9Wx3LWr0w16uNCN0m8gwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3\n' - 'DQEBDQUAA4ICAQBIWgVnD+CPKbpWha/KIka90rLfDyQtgItuAqNb6z14OI/l7sya\n' - 'XIbVtgAcnGBPlJBeXcd70njrQOsjLIniTL1UMoTJW2AFYe1qcTZmRD3QK+piVR3S\n' - 'yYj4PgMR1zdLxPv8iTX50DcLh7fGB3dNdA5VSF3Zax/0/ijkcqXsfaeJJ/ffQwpQ\n' - 'X3Lk5+6ub4q3AGjyUELw8IJajkWGu9j8EehE/2cXYpwYoOjICzht9PmX/u2dNu9T\n' - 'teKCu5lPpTnl/9yO3upZsBeP1LVr4RCWBgGYcjT3Ht4JqzcSkt4Vc5bNeP1U3oL8\n' - 'a5Qec4TgcBaOMrECGEGES9ieQsJ6aGK5qQMR3ymnD9kUUv7qWv0uX4C3iUQRY9yz\n' - '115wxR3oFiUgO4SgrphPXResAvI3V5aWxFONbY60m5hxOjaKfNGqySXUNfLyzjxz\n' - 'PCsZOGCze1kpSIrCStGAvZxsAGtjEaCNx3dHZamUD09k68L67TNL/m3UBzOv+hPd\n' - 'tQlU+E0vr9hbH44BJoV56TVL27+m6TbuLEDPudtoPJFqSCsD9DKMTwqQDuaruwYk\n' - 'xCNz7RbPeWGMTo+MSse0j2Al7XPV8bXz/wAr4TiDvX2JPk0+41WNiZD5RtLiDdai\n' - '5aRxNM/8UEsn/byEzZb1lv2CF3f5MQ1LMRu7GrQvjlaqhaoO2lG+8ZapiQ==\n' + 'MIIC7jCCAdYCAQEwDQYJKoZIhvcNAQEFBQAwPDEnMCUGA1UECgweQ2hlY2tfTUsg\n' + 'U2l0ZSBrb2NoYmFja2tvY2hiYWNrMREwDwYDVQQDDAhjbWthZG1pbjAgFw0yNDA0\n' + 'MTAxMjA4MjdaGA8yMDU0MDQwMzEyMDgyN1owPDEnMCUGA1UECgweQ2hlY2tfTUsg\n' + 'U2l0ZSBrb2NoYmFja2tvY2hiYWNrMREwDwYDVQQDDAhjbWthZG1pbjCCASIwDQYJ\n' + 'KoZIhvcNAQEBBQADggEPADCCAQoCggEBALkWEToPVSC8ibmNqhgTnN9WozwIb4pi\n' + 'gsrEnhzGC/GW65aJBe+yUlAtVd+PBnTfUwG+ibA2pZ7Bcc+M4FDx/87631ms4EVZ\n' + 'KGeAWrDvxgJsMYWb0O2M0HWuAWnCV2xeu5yIcE+XbPhoxVsxMDUsy2uJVgNMvSIS\n' + 'mV+POBBjJAEFQSCibL8nNzlRU6gNXhPk49xxs2daUfpL17gO2laywux8UtFJqE21\n' + 'v+86Z4MQjDxYxpNUC9/sHHCJ97alMPJa7XJLOAUCPjHH7UWorhKCyIkzA03TIj46\n' + 'Cgg2qrclh/4hnBzm5+NrdW02Wm62FHPiz1Z5L9UtYs2OvYX3XeEdGY0CAwEAATAN\n' + 'BgkqhkiG9w0BAQUFAAOCAQEARHLoPwMC9o1fDSAQSYfaTE09RtsrpOTXBmaNqpYR\n' + 'PWqtA5Uz0X7+LEnkMrTkQZ7gI6FQ6PItFcE4W+AkXZLK3JmJIcktJlKoDIQwdXV6\n' + 'DrJgDAIHc7UnSDkgeTYegnQoNmT3Q6uZUm2yaK4AgN0fEEtg3HYgw4ltc2KaqQM8\n' + 'vtlEamGx85gCNUGPugJaP71FoE+t1qi0dGFQ+RUcHUBHlhrMzAd80K+Ctp8uKIs/\n' + 'Zu3h3eprE6JKPNqIdg38qGMlkI2RS9ZDFMIm4CDLp+10ZDPr0Muuvk03v82s2Tjd\n' + 'NVxXHH881oAVucR4LHX3C8YwQW7ryrSOngKBl35gmOIq+A==\n' '-----END CERTIFICATE-----\n', - 'date': 1692013686.5423424, - 'not_downloaded': True, + 'date': 1712750907.4960656, 'owner': 'cmkadmin', 'private_key': '-----BEGIN ENCRYPTED PRIVATE KEY-----\n' - 'MIIJrTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIWYm0HAdMN4oCAggA\n' - 'MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBCRS4eQmm1Od053ZwlDWnzjBIIJ\n' - 'UPpZz/9lJiA9M1r6XUon59zO+/rhWCQe1c6J1xBQec1GeGcMPok0Roq7j3j8O0zC\n' - '1VGxSUcXpF8EENY1sT28uvyuuqD4h6659Gz08f9nEsL+CChvd/z6MD4ac7jKwlmf\n' - 'mU7wKZYTha24V0iHvimtFA+ygWWiJyLZ7AzGHNm9CNN7C/TyAkaqiCBncM0uKmNz\n' - 'ppQV8hgm9Wv/PcqheVeGP0feZaW3jcwqvzXrCfdTHqYIhvo91i4Zf8dnwWE/kcRn\n' - 'TUGZ5tQakIyN8uW9dY4YyOzrw28bOqaakusNRJbfem8PazRNedDhfeb14sQWLTGI\n' - 'v8IkZJrPGfM1PIxEZXGsfjISagpw6st8BQMsPyhieawD1wr+kLZrAsQ1sLcLWUgU\n' - 'C8A3L0Gp0d4BZa3gHeIZEztxsVKBu/9N17srBLvRHQnpM7DYrL/XtP4LjbxNmnOI\n' - 'zOP8Pl8dCeJjGrYLEleF4u4qkLR43dl6xwdAhudQsQeBeM5ognxTkEbsZG/FTWmL\n' - 'boH6DYdEZz2dr1cPK6T00BJA49t9RGauTXyY8gtIa2Cdk/PAXPre0RKzUHHWqj2V\n' - 'c/dBIXWtuiZgto9RTKd1mT0ErI94okgySVNjUw+4yI94gxRHyNxgB3M2cMQ/rgVl\n' - 'eDeSLQ0d1VpROh2DGl0I3JGjVprXydTaMVuFtzk9UgBcbX2Lgtloqk/YXnOYHQ8d\n' - '2l42HQIPpHIL0X2w6DMGfoEK9NZPKzkv8EmGba7zeItoLPv97+Z1rZP9HL8u2czH\n' - 'dkMVnj3sUpGK31pN50s+hwXoxnwoih9sugDcKzNxQnSqOe2Y34iAtcMcDg6D5Fq3\n' - 'd2pEu4AoQRkzASHED/wH1mETfLtVm8HxVEOog4LMU+JKbLkiU5i5zh3UjyLrEJmB\n' - 'kJdhrx2Xdfyc5QJZeLdGVKy+3gv9n1W0wwoHmQi+QVp77/xXz3vVW+Tfk0aqIb42\n' - 'LyYlqZwsP2HggoJFKVlo7YuEBNX2/ctJGuufslTVkzSAUq99+rxnVniCK4es3kME\n' - 'stpgG11khMnK92Dpnrv17g8I0LTVVGsSbC6pZgIC9kPStDN/ilRd2DipCyM7Q9G0\n' - '32DSr1ukN3VSsMz6t0A+lGD3PWcwCuhXbgSafGmmYEyYBWu20s+zud4C/hHp4W7j\n' - '7t5wDl6ZoweleqMWj7GBmttKX3S7gZBbfcsN4pGOAWprIt8ADhfCK0ag1aHtZjYF\n' - 'QAaF9sJu/HjX8fyh7xT2MUNTzlLWVbhqzT8jWFGthNdt+uT/Fv5tFoZ8E0tTbOP/\n' - 'C7Z2XB3V34opahCno4ss4urMF28drGKu2KaECOcSE7iCQdaAz2quPfkXwymbRiVt\n' - 'adMZGU37lyWBBn2df9kUV1pfjSm+KcAVOWMiQYpyNCiHkO4lbdUkRMQnEmuk+yeF\n' - 'Yah2iHl8zCspoqxuBDiGlPTZkReXoGfTfZKIx5AZt6iLlQ/bq8I1C9vTUrtfTVx2\n' - 'RMISnTlEH5bWpCyxnwLRBIWSwtzRNngB3P4huk5Vh0c8Q5scjLXCG5pk1uFjoPoA\n' - 'xmLojoRZLa09SNBPzZAHX8SIATj9pvBkBJCqx8gXEtW88j6/J0q16499p3U6zljH\n' - 'ec5y2kr064nEoX1i4WiuV8PxtOK86zJP1w2lwLvjqZ2o1RGhX/05mYPrIAyCzzhT\n' - 'uQ77W3lALtWzBZ87kWlwgGGHRddyQBVa2PqRUHpYJqhANVYQOrkSJQdgKN66xqbc\n' - 'UBjlFroWktYxzZMrxPSI/R5Fm72w+toDlGxiU4GIgXAwxcWjmHI/O70lxqwwC+EV\n' - 'XnFGPXWfvZYTSteO5hSviIVcxiJq/G66D7L7VByuP4TjH6VMNKN1UFyIjD7jT5OJ\n' - '5y4Zx25mZ6ulTAnkYMLnC7KXcCT4sehmx38KjDDsx+waZbbmyGygFe6bIMX60Mz/\n' - 'hvuRcJTzWMSRhaDekxP6ivYx8RSJEhFlZnqfuKmSN0TGE8JjTTBjTE7CYKsNGa/N\n' - '598xQmFNxHV8hjtQqADIhHgMZ+rxQATgP4jUxgOh9xo4sDMFLUcL+wiaorl5vNfl\n' - 'cf3dE9eQ9ULt8dOjKqIXpw4T/6J6iMgOoAWFVhu6XpZeOQX7tfD3xk3ht/OC6sV7\n' - '3FDjEL6rSVbOi999Y4nvaCWreKBUBdAOtsq5aqKgU15Awd9kIkfIFbbblvoGHvxs\n' - '8mX6HTVXnrlMX2qKtmFjynzerR0qDZruD95+4FFI4JtwNuMnRAOjsaKu3VT4Hfkx\n' - 'KQBxOqLaKIOPXfoeT4H098FCSP8QojMZfpqbJdNs2KcjM8131bIvIQRyRZlBY5C8\n' - '33NnDx7IxOhIx1wqjbohLfPs1wAWXdBuuul3YP5K7Kx9VetbfYP6IEp02XjG2XvG\n' - 'GchTQ4IPQRRnuY+3cgv4XGFbI4xKc+9CnHgjLA2cgNdruVuUv9qBjEhpA5j7L845\n' - 'w2Y1tOa+ApgawYxvh4rqM29+GnXDreucySwuy+iofXxuQm4SDYdquMzDcQyQ36fk\n' - 'afexK0PT9SGE8U/xtVDPc0EDe5ZrTymglf4pB0/rzpgvGFDot+wdzNXhygpz2Cfq\n' - 'TGRDj0Fg9rbwZr9bX4lBy/bqaCzjIa6rbnDJRtLloi7NXNFoUja6zHnDunbZAQC2\n' - 'rHn9Z0KAeN1jnsB6L57b9jukfZUJgwi7k7aSf6Nh6zOZcZDctGvGJ9ky6TQI0K9s\n' - '9SPsKumK9dDjh1jrXHYxVA+PKjNilza9MUnLwWzOmzIfLaCOgWoanymeOwbm7t/h\n' - '1Cg+rk5Whmk7mdv9H/Kj11DnSR620DktEQAuDw6oB8rdF0M1SxD/titol0U+lOpp\n' - '3mSFP4DMPDuP/rn+aCJaUUKoBrk/17jl3esbkGbqauB2NqieS7/CSVfse/BNqVeG\n' - 'oWId00lqYJSkrhDP5X0WdK3EZSrq4BCu7ynDN06gFfu5dj//1pO0WpP87bCAK3hl\n' - 'U3wkppegmaKZZ4XB28l9uX1fMkIXBf63u+UMC8PkjRzrXX2xC+sUTaaAmbYgWELJ\n' - 'U8sJe5t4bcUtpZbxreDGFHb1IONnp5H7d8yE0Qol/jCt9voklc8AdFG414qZxDsL\n' - 'WM3QD15Sq/H5f8i8qe4B9SH0FAmGY14s0W5fZL4Z4os2vBfzLpWZWCXgP6YmWVJG\n' - 'jgeR+zh52RajaGqEvCNmvvBVovKLLTQ/ds/KCctHd3zL\n' - '-----END ENCRYPTED PRIVATE KEY-----\n'}}) \ No newline at end of file + 'MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIgozcjYS2N2wCAggA\n' + 'MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBB/AJDeg9Ovz9WFEiIU7M/xBIIE\n' + '0HwKBbznuz3iKq2PU/pPkx/2RmjmZJ++TLjtpznhTphHvg9kJ9HLgDPquAniLoGu\n' + 'tpEUa8fjBb7tkg/abznP/PCjRA3eAobGkfir+t0Iqk165V7wc+ePhukKGWiOzSQa\n' + 'TEqKKQSPKPEyJCbOFtGXb3YiqfhHwmiAdMTH3GkfprfesOqS5ooCCW7kMpnYeB2z\n' + 'tIx62fHXz6/338v0X6OTEZryYoVPyvFijYXGix6/wlj1BdMtuk2LLCCdfHUsZmDU\n' + 'tcWfTIp/kibJXJ4Ss4EsaT/d02s3ZegBeY9hgq2n4oe99yje67iGMPdSTqVNkToe\n' + 'aLf0RWwz1Rb6X2Ha4oN/xyKd+Duw4ikqa+hhq6pNs4ycOLaCFSFd3FaESCt/dzmL\n' + '3JWpuvBaSySGrimS5/ZXolMKu/kNPv0S6LfWHnJS/NFuNzw6nWBb2d15LpJDZFC3\n' + '0L/p3hUNUOn1hEu0+GFmMiKQCStKArC49HNvS7ZqAAVVGjQ+fJBb8EYRUIlR6UJU\n' + 'i9LyhRrdNhP1IUM3dMOWCPKIgC3jArGF9ZOSginn9bv5ghkalWVvz3JGhjl+g+jU\n' + 'fKeX/B61DCqDCYxrjM5RsPUybLkleOCfFa1n1cRumJpOAvi3nIf0hwiVq1HgV5wQ\n' + '6jmrJB8rUdiHLNCbC/smeQKzHlC5w0XXCBJTCpKL5v8esOzs8NtQxE9NfyF2343I\n' + '92Ns6GGz96Anem1XHKfnoPvitbKtb5KIfPq0ffFPFu5xzhC0GZWNowdXrlR/PJ+E\n' + '+3COntBBgtWysL+Cf7yCFv7M9vCNnrRkaE3X55sbPLET7KKW4pCk9qCuL0je3hya\n' + 'pJ/TTzxckuTC52uuaU0GmWyWgxUnNRObSI8yU4MBqC/e2nkURMdYpR6IaqzoH+O1\n' + '2AiQytx+yZpia7ndvi25Sao56ZSi8KPZx/DUFX2r4REjtibGxYbbyY9xHfNWg//l\n' + '5iEPBhCLk4xaofVz4NH59ubTO2G9+gQ6FPQ2vi07i1csCzBOcQIWLvXzetRvczvn\n' + 'TeRFc9dDBUAOBSdSuw0x1MagfRTKto2ASPSELYcQGJJvWVso3y4V0uGBziv9gbbR\n' + 'V2ZpSvqbpI3zojr7okwpDv72PcgmBChkQ1EugyW4N0qLxUVv+NhuHC11qNGGSWvp\n' + '1w3e3kFZ+ggdWZCxbvmV9YVSkdVw3KlOFWPXQPdk5et5wnEFrTxPTC+HG4MKs5SY\n' + 'fvB1/X3HN2qD684Q0xgOjkQoWoCQGlr4rwCvytbE9OQDwzPlvrA7isBrYwYA1Q0S\n' + 'XzpU9CJO2t4i4ONi2R6RQQYFMejTZ9g3p9rEw6xfxN3073rTJnkbzMDF5zS2Qj/X\n' + '6aVJw/322nTQcNEGl8RtY+0jRisAbch9JJPNIcXZRHDWMFroCbtScVsTPJKie9yR\n' + 'A3gDoR4pJMJ+tgSpADfFAAg1KfG9VGRERULkwFHZCt+micNASqU88jVaxHK6U29D\n' + 'MXq6z0//07wWpeR39yA+i3s462fLDgs3tqp0FoVVf9Wbur3FhOjsDAkV1yh/uK9e\n' + 'UAf69KPWfTH5awkmpM0Yz76qV+L4B/QczQKWPtUzlRJxvAeKGfHkD1UIPkMUPmQQ\n' + 'fNw0rolGI0G47R2/78ouGbsySM+FPZNkMMI/YIEN0f4Y\n' + '-----END ENCRYPTED PRIVATE KEY-----\n'}}) + From 51f6618f9cc270d4b73b1693ef62488d96d87127 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Mon, 15 Apr 2024 16:38:37 -0400 Subject: [PATCH 113/117] Add ignore file for next ansible-core release. --- tests/sanity/ignore-2.18.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/sanity/ignore-2.18.txt diff --git a/tests/sanity/ignore-2.18.txt b/tests/sanity/ignore-2.18.txt new file mode 100644 index 000000000..439637947 --- /dev/null +++ b/tests/sanity/ignore-2.18.txt @@ -0,0 +1,4 @@ +tests/container/files/systemctl3.py pep8!skip +tests/container/files/systemctl3.py pylint!skip +tests/container/files/systemctl3.py shebang!skip +tests/container/files/systemctl3.py compile-3.12!skip \ No newline at end of file From bde94779def6b0b8f9be19a622156d7be2f06bcc Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 16 Apr 2024 16:00:55 -0400 Subject: [PATCH 114/117] Try to clarify option description. --- plugins/modules/folder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index d955c0e66..9a9a497e0 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -31,7 +31,7 @@ required: true type: str name: - description: The name (title) of your folder. If omitted defaults to the folder-name from path. + description: The name (title) of your folder. If omitted defaults to the string after the last C(/) in I(path). type: str aliases: [title] attributes: From afc6321ad07f2dee579d650fd4d0793b51588402 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 16 Apr 2024 16:01:46 -0400 Subject: [PATCH 115/117] Add release summary. --- changelogs/fragments/release_summary.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/fragments/release_summary.yml diff --git a/changelogs/fragments/release_summary.yml b/changelogs/fragments/release_summary.yml new file mode 100644 index 000000000..d834803be --- /dev/null +++ b/changelogs/fragments/release_summary.yml @@ -0,0 +1 @@ +release_summary: "Spring is here! With a rewritten host module including check mode and cluster support." From 0216c377fb06813e3c93ae60bdeab439f5a03b0a Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 16 Apr 2024 16:03:16 -0400 Subject: [PATCH 116/117] Bump Checkmk versions. --- roles/agent/README.md | 2 +- roles/agent/defaults/main.yml | 2 +- roles/agent/molecule/2.1.0/group_vars/all.yml | 2 +- roles/agent/molecule/2.2.0/group_vars/all.yml | 2 +- roles/server/README.md | 2 +- roles/server/defaults/main.yml | 2 +- roles/server/molecule/2.1.0/group_vars/all.yml | 2 +- roles/server/molecule/2.2.0/group_vars/all.yml | 2 +- scripts/release.sh | 4 ++-- tests/integration/targets/activation/vars/main.yml | 6 +++--- tests/integration/targets/bakery/vars/main.yml | 4 ++-- tests/integration/targets/contact_group/vars/main.yml | 6 +++--- tests/integration/targets/discovery/vars/main.yml | 6 +++--- tests/integration/targets/downtime/vars/main.yml | 6 +++--- tests/integration/targets/folder/vars/main.yml | 6 +++--- tests/integration/targets/host/vars/main.yml | 6 +++--- tests/integration/targets/host_group/vars/main.yml | 8 ++++---- tests/integration/targets/lookup_bakery/vars/main.yml | 4 ++-- tests/integration/targets/lookup_folder/vars/main.yml | 6 +++--- tests/integration/targets/lookup_folders/vars/main.yml | 6 +++--- tests/integration/targets/lookup_host/vars/main.yml | 6 +++--- tests/integration/targets/lookup_hosts/vars/main.yml | 6 +++--- tests/integration/targets/lookup_rules/vars/main.yml | 6 +++--- tests/integration/targets/lookup_rulesets/vars/main.yml | 6 +++--- tests/integration/targets/lookup_version/vars/main.yml | 6 +++--- tests/integration/targets/password/vars/main.yml | 8 ++++---- tests/integration/targets/rule/vars/main.yml | 6 +++--- tests/integration/targets/service_group/vars/main.yml | 8 ++++---- tests/integration/targets/tag_group/vars/main.yml | 8 ++++---- tests/integration/targets/timeperiod/vars/main.yml | 6 +++--- tests/integration/targets/user/vars/main.yml | 8 ++++---- 31 files changed, 79 insertions(+), 79 deletions(-) diff --git a/roles/agent/README.md b/roles/agent/README.md index 1d28cd07f..57790fc78 100644 --- a/roles/agent/README.md +++ b/roles/agent/README.md @@ -13,7 +13,7 @@ It can be installed as easy as running: ## Role Variables - checkmk_agent_version: "2.2.0p23" + checkmk_agent_version: "2.2.0p24" The Checkmk version of the site your agents will talk to. diff --git a/roles/agent/defaults/main.yml b/roles/agent/defaults/main.yml index e43d0f13a..78ecb81d2 100644 --- a/roles/agent/defaults/main.yml +++ b/roles/agent/defaults/main.yml @@ -1,5 +1,5 @@ --- -checkmk_agent_version: "2.2.0p23" +checkmk_agent_version: "2.2.0p24" checkmk_agent_edition: cre checkmk_agent_server_protocol: http checkmk_agent_server: localhost diff --git a/roles/agent/molecule/2.1.0/group_vars/all.yml b/roles/agent/molecule/2.1.0/group_vars/all.yml index 1437d561b..6c91ff137 100644 --- a/roles/agent/molecule/2.1.0/group_vars/all.yml +++ b/roles/agent/molecule/2.1.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.1.0p40" +checkmk_var_version: "2.1.0p41" checkmk_var_edition: "cre" checkmk_var_checkmk_site: "my_site" checkmk_var_automation_user: "cmkadmin" diff --git a/roles/agent/molecule/2.2.0/group_vars/all.yml b/roles/agent/molecule/2.2.0/group_vars/all.yml index 6a8503c5c..b86a54e9c 100644 --- a/roles/agent/molecule/2.2.0/group_vars/all.yml +++ b/roles/agent/molecule/2.2.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.2.0p23" +checkmk_var_version: "2.2.0p24" checkmk_var_edition: "cre" checkmk_var_checkmk_site: "my_site" checkmk_var_automation_user: "cmkadmin" diff --git a/roles/server/README.md b/roles/server/README.md index 864eda075..fbd3cedef 100644 --- a/roles/server/README.md +++ b/roles/server/README.md @@ -25,7 +25,7 @@ To learn about the distributions used in automated tests, inspect the correspond ## Role Variables - checkmk_server_version: "2.2.0p23" + checkmk_server_version: "2.2.0p24" The global Checkmk version. This is used for installing Checkmk. To manage sites and their version, see `checkmk_server_sites`. diff --git a/roles/server/defaults/main.yml b/roles/server/defaults/main.yml index b9b7c2edd..da17553c1 100644 --- a/roles/server/defaults/main.yml +++ b/roles/server/defaults/main.yml @@ -24,7 +24,7 @@ checkmk_server_server_stable_os: - Ubuntu-20 - Ubuntu-22 -checkmk_server_version: "2.2.0p23" +checkmk_server_version: "2.2.0p24" checkmk_server_edition: cre checkmk_server_verify_setup: 'true' diff --git a/roles/server/molecule/2.1.0/group_vars/all.yml b/roles/server/molecule/2.1.0/group_vars/all.yml index 62c495f0e..66bcd07b4 100644 --- a/roles/server/molecule/2.1.0/group_vars/all.yml +++ b/roles/server/molecule/2.1.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.1.0p40" +checkmk_var_version: "2.1.0p41" checkmk_var_edition: "cre" checkmk_server_verify_setup: 'true' checkmk_var_server_url: "http://127.0.0.1/" diff --git a/roles/server/molecule/2.2.0/group_vars/all.yml b/roles/server/molecule/2.2.0/group_vars/all.yml index a65cf8c29..b454a1404 100644 --- a/roles/server/molecule/2.2.0/group_vars/all.yml +++ b/roles/server/molecule/2.2.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_var_version: "2.2.0p23" +checkmk_var_version: "2.2.0p24" checkmk_var_edition: "cre" checkmk_server_verify_setup: 'true' checkmk_var_server_url: "http://127.0.0.1/" diff --git a/scripts/release.sh b/scripts/release.sh index 6342e3fc8..8c003f1ee 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -16,8 +16,8 @@ collection_dir="${script_dir%/*}" # Update these as necessary: checkmk_ancient="2.0.0p39" -checkmk_oldstable="2.1.0p40" -checkmk_stable="2.2.0p23" +checkmk_oldstable="2.1.0p41" +checkmk_stable="2.2.0p24" while getopts 's:t:' OPTION; do case "$OPTION" in diff --git a/tests/integration/targets/activation/vars/main.yml b/tests/integration/targets/activation/vars/main.yml index 91e8ed7ad..51ed346c9 100644 --- a/tests/integration/targets/activation/vars/main.yml +++ b/tests/integration/targets/activation/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/bakery/vars/main.yml b/tests/integration/targets/bakery/vars/main.yml index 2d72d28d5..8dc3b3562 100644 --- a/tests/integration/targets/bakery/vars/main.yml +++ b/tests/integration/targets/bakery/vars/main.yml @@ -1,9 +1,9 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cee" site: "old_cee" diff --git a/tests/integration/targets/contact_group/vars/main.yml b/tests/integration/targets/contact_group/vars/main.yml index f851cd39c..64b3a3293 100644 --- a/tests/integration/targets/contact_group/vars/main.yml +++ b/tests/integration/targets/contact_group/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/discovery/vars/main.yml b/tests/integration/targets/discovery/vars/main.yml index 34512dca5..baacf997c 100644 --- a/tests/integration/targets/discovery/vars/main.yml +++ b/tests/integration/targets/discovery/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/downtime/vars/main.yml b/tests/integration/targets/downtime/vars/main.yml index 91e8ed7ad..51ed346c9 100644 --- a/tests/integration/targets/downtime/vars/main.yml +++ b/tests/integration/targets/downtime/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/folder/vars/main.yml b/tests/integration/targets/folder/vars/main.yml index e5b3868cb..8097a75d4 100644 --- a/tests/integration/targets/folder/vars/main.yml +++ b/tests/integration/targets/folder/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/host/vars/main.yml b/tests/integration/targets/host/vars/main.yml index 82f4fde49..6a8fd31c4 100644 --- a/tests/integration/targets/host/vars/main.yml +++ b/tests/integration/targets/host/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/host_group/vars/main.yml b/tests/integration/targets/host_group/vars/main.yml index ea40fab2c..0daee776d 100644 --- a/tests/integration/targets/host_group/vars/main.yml +++ b/tests/integration/targets/host_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cme" site: "stable_cme" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_bakery/vars/main.yml b/tests/integration/targets/lookup_bakery/vars/main.yml index bddbccdff..554d567ff 100644 --- a/tests/integration/targets/lookup_bakery/vars/main.yml +++ b/tests/integration/targets/lookup_bakery/vars/main.yml @@ -1,8 +1,8 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cee" site: "old_cee" diff --git a/tests/integration/targets/lookup_folder/vars/main.yml b/tests/integration/targets/lookup_folder/vars/main.yml index 46475a44b..6cb3eb9ef 100644 --- a/tests/integration/targets/lookup_folder/vars/main.yml +++ b/tests/integration/targets/lookup_folder/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_folders/vars/main.yml b/tests/integration/targets/lookup_folders/vars/main.yml index e738dac4b..08bf5faba 100644 --- a/tests/integration/targets/lookup_folders/vars/main.yml +++ b/tests/integration/targets/lookup_folders/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_host/vars/main.yml b/tests/integration/targets/lookup_host/vars/main.yml index cd18b47b3..3fb8f7a57 100644 --- a/tests/integration/targets/lookup_host/vars/main.yml +++ b/tests/integration/targets/lookup_host/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_hosts/vars/main.yml b/tests/integration/targets/lookup_hosts/vars/main.yml index 6b443cd28..cd76290b6 100644 --- a/tests/integration/targets/lookup_hosts/vars/main.yml +++ b/tests/integration/targets/lookup_hosts/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/lookup_rules/vars/main.yml b/tests/integration/targets/lookup_rules/vars/main.yml index 10c7b2387..66144c474 100644 --- a/tests/integration/targets/lookup_rules/vars/main.yml +++ b/tests/integration/targets/lookup_rules/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/lookup_rulesets/vars/main.yml b/tests/integration/targets/lookup_rulesets/vars/main.yml index 497ef4d06..c586b1e5f 100644 --- a/tests/integration/targets/lookup_rulesets/vars/main.yml +++ b/tests/integration/targets/lookup_rulesets/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/lookup_version/vars/main.yml b/tests/integration/targets/lookup_version/vars/main.yml index 12e5f3e2d..1d2102698 100644 --- a/tests/integration/targets/lookup_version/vars/main.yml +++ b/tests/integration/targets/lookup_version/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/password/vars/main.yml b/tests/integration/targets/password/vars/main.yml index b61b76dd1..01c5bbf77 100644 --- a/tests/integration/targets/password/vars/main.yml +++ b/tests/integration/targets/password/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cme" site: "stable_cme" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/rule/vars/main.yml b/tests/integration/targets/rule/vars/main.yml index cee5dc35d..3ad9d6726 100644 --- a/tests/integration/targets/rule/vars/main.yml +++ b/tests/integration/targets/rule/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/service_group/vars/main.yml b/tests/integration/targets/service_group/vars/main.yml index 69dd7d45a..fdedc14c7 100644 --- a/tests/integration/targets/service_group/vars/main.yml +++ b/tests/integration/targets/service_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cme" site: "stable_cme" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/tag_group/vars/main.yml b/tests/integration/targets/tag_group/vars/main.yml index 2f9a970df..9f5653ddd 100644 --- a/tests/integration/targets/tag_group/vars/main.yml +++ b/tests/integration/targets/tag_group/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cme" site: "stable_cme" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" - version: "2.0.0p39" diff --git a/tests/integration/targets/timeperiod/vars/main.yml b/tests/integration/targets/timeperiod/vars/main.yml index 2f1fe09fb..3e7fc5176 100644 --- a/tests/integration/targets/timeperiod/vars/main.yml +++ b/tests/integration/targets/timeperiod/vars/main.yml @@ -1,12 +1,12 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" diff --git a/tests/integration/targets/user/vars/main.yml b/tests/integration/targets/user/vars/main.yml index 40e3cb361..ef68bfe74 100644 --- a/tests/integration/targets/user/vars/main.yml +++ b/tests/integration/targets/user/vars/main.yml @@ -1,15 +1,15 @@ --- test_sites: - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cme" site: "stable_cme" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cre" site: "stable_cre" - - version: "2.2.0p23" + - version: "2.2.0p24" edition: "cee" site: "stable_cee" - - version: "2.1.0p40" + - version: "2.1.0p41" edition: "cre" site: "old_cre" From 1b08e06e70b2388c9a0b19498d157b91f0fcf390 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 16 Apr 2024 16:03:25 -0400 Subject: [PATCH 117/117] Bump collection version. --- SUPPORT.md | 1 + galaxy.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SUPPORT.md b/SUPPORT.md index 0cfd59c95..d4019f2ca 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -51,3 +51,4 @@ Collection Version | Checkmk Versions | Ansible Versions | Remarks 4.2.0 | 2.0.0p39, 2.1.0p38, 2.2.0p19 | 2.14, 2.15, 2.16 | None 4.3.0 | 2.0.0p39, 2.1.0p39, 2.2.0p22 | 2.14, 2.15, 2.16 | None 4.3.1 | 2.0.0p39, 2.1.0p39, 2.2.0p22 | 2.14, 2.15, 2.16 | None +4.4.0 | 2.0.0p39, 2.1.0p41, 2.2.0p24 | 2.14, 2.15, 2.16 | None diff --git a/galaxy.yml b/galaxy.yml index f4f35b8cd..0a06a45bb 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -10,7 +10,7 @@ name: general # The version of the collection. Must be compatible with semantic versioning -version: 4.3.1 +version: 4.4.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md