From 28fa2561a29637e340242dc791cf9c21ad45b167 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 31 Jan 2024 15:11:27 +0100 Subject: [PATCH 1/6] add: parents parsing --- plugins/modules/folder.py | 9 +++++++++ plugins/modules/host.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index e2f6a5c5e..a928bf4a7 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -148,6 +148,7 @@ # https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/import.html from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.dict_transformations import dict_merge +from ansible.module_utils.common.validation import check_type_list from ansible.module_utils.urls import fetch_url PYTHON_VERSION = 3 @@ -424,6 +425,14 @@ def run_module(): if attributes == []: attributes = {} + if attributes or attributes != {}: + if attributes.get("parents"): + attributes["parents"] = check_type_list(attributes.get("parents")) + + if update_attributes or update_attributes != {}: + if update_attributes.get("parents"): + update_attributes["parents"] = check_type_list(update_attributes.get("parents")) + state = module.params.get("state", "present") # Determine the current state of this particular folder diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 63301f621..920c118a5 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -164,6 +164,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.dict_transformations import dict_merge +from ansible.module_utils.common.validation import check_type_list from ansible.module_utils.urls import fetch_url @@ -350,6 +351,14 @@ def run_module(): update_attributes = module.params.get("update_attributes", {}) state = module.params.get("state", "present") + if attributes != {}: + if attributes.get("parents"): + attributes["parents"] = check_type_list(attributes.get("parents")) + + if update_attributes != {}: + if update_attributes.get("parents"): + update_attributes["parents"] = check_type_list(update_attributes.get("parents")) + if module.params["folder"]: module.params["folder"] = normalize_folder(module.params["folder"]) From 3cd34839542fbc03ab0c846ac69ef2a3e0c7de9c Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 31 Jan 2024 15:13:55 +0100 Subject: [PATCH 2/6] fix: style --- plugins/modules/folder.py | 4 +++- plugins/modules/host.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index a928bf4a7..4f75a6eb5 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -431,7 +431,9 @@ def run_module(): if update_attributes or update_attributes != {}: if update_attributes.get("parents"): - update_attributes["parents"] = check_type_list(update_attributes.get("parents")) + update_attributes["parents"] = check_type_list( + update_attributes.get("parents") + ) state = module.params.get("state", "present") diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 920c118a5..eba3923ac 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -357,7 +357,9 @@ def run_module(): if update_attributes != {}: if update_attributes.get("parents"): - update_attributes["parents"] = check_type_list(update_attributes.get("parents")) + update_attributes["parents"] = check_type_list( + update_attributes.get("parents") + ) if module.params["folder"]: module.params["folder"] = normalize_folder(module.params["folder"]) From 7d80401c5746c417ec91e4f59fc5dbb1934da5e8 Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Wed, 31 Jan 2024 15:29:16 +0100 Subject: [PATCH 3/6] fix: check --- plugins/modules/folder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index 4f75a6eb5..103a199f0 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -425,11 +425,11 @@ def run_module(): if attributes == []: attributes = {} - if attributes or attributes != {}: + if attributes and attributes != {}: if attributes.get("parents"): attributes["parents"] = check_type_list(attributes.get("parents")) - if update_attributes or update_attributes != {}: + if update_attributes and update_attributes != {}: if update_attributes.get("parents"): update_attributes["parents"] = check_type_list( update_attributes.get("parents") From bce20d324e9b14cf3f9ceaefb86573f1be78c35d Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Fri, 9 Feb 2024 11:51:10 +0100 Subject: [PATCH 4/6] refactor: request --- plugins/modules/host.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index eba3923ac..8ad85d400 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -351,15 +351,12 @@ def run_module(): update_attributes = module.params.get("update_attributes", {}) state = module.params.get("state", "present") - if attributes != {}: - if attributes.get("parents"): - attributes["parents"] = check_type_list(attributes.get("parents")) - - if update_attributes != {}: - if update_attributes.get("parents"): - update_attributes["parents"] = check_type_list( - update_attributes.get("parents") - ) + 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"]) From eaa49101f98b67d08410ceb8ae7416d00a7069db Mon Sep 17 00:00:00 2001 From: Michael Sekania Date: Fri, 9 Feb 2024 15:00:00 +0100 Subject: [PATCH 5/6] fix: style --- plugins/modules/host.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/modules/host.py b/plugins/modules/host.py index 8ad85d400..1be564dd0 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -354,9 +354,7 @@ def run_module(): for par in [attributes, update_attributes]: if par != {}: if par.get("parents"): - par["parents"] = check_type_list( - par.get("parents") - ) + par["parents"] = check_type_list(par.get("parents")) if module.params["folder"]: module.params["folder"] = normalize_folder(module.params["folder"]) From 0d43296287d4a0544f3a1d275250be7f7f3c2804 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 14 Feb 2024 11:37:52 +0100 Subject: [PATCH 6/6] Blackenedgit add plugins/modules/folder.py --- plugins/modules/folder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/folder.py b/plugins/modules/folder.py index 25a73449e..87a5a9945 100644 --- a/plugins/modules/folder.py +++ b/plugins/modules/folder.py @@ -508,7 +508,6 @@ def run_module(): changed=False, ) - desired_state = current_folder.params.get("state") if current_folder.state == "present": result = result._replace(