Skip to content

Commit

Permalink
[ignore] Add variable for keys to be sanitized in constants.py file.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmicol committed Jan 22, 2025
1 parent d95d548 commit 676bfe4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions plugins/module_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@
INTERFACE_FLOW_RULES_STATUS_MAPPING = {"enabled": "ENABLED", "disabled": "DISABLED"}

ND_SETUP_NODE_ROLE_MAPPING = {"primary": "Master", "secondary": "Worker", "standby": "Standby"}

ND_REST_KEYS_TO_SANITIZE = ["metadata"]
8 changes: 4 additions & 4 deletions plugins/modules/nd_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.nd.plugins.module_utils.nd import NDModule, nd_argument_spec, sanitize
from ansible_collections.cisco.nd.plugins.module_utils.constants import ND_REST_KEYS_TO_SANITIZE
from ansible.module_utils._text import to_text


Expand Down Expand Up @@ -214,23 +215,22 @@ def main():
module.fail_json(msg=error_msg, payload=content)

method = nd.params.get("method").upper()
keys_to_sanitize = ["metadata"]

# Append previous state of the object
if method in ("PUT", "DELETE", "PATCH"):
nd.existing = nd.previous = sanitize(nd.query_obj(path, ignore_not_found_error=True), keys_to_sanitize)
nd.existing = nd.previous = sanitize(nd.query_obj(path, ignore_not_found_error=True), ND_REST_KEYS_TO_SANITIZE)
nd.result["previous"] = nd.previous

# Perform request
if module.check_mode:
nd.result["jsondata"] = content
else:
nd.result["jsondata"] = nd.request(path, method=method, data=content, file=file_path)
nd.existing = sanitize(nd.result["jsondata"], keys_to_sanitize)
nd.existing = sanitize(nd.result["jsondata"], ND_REST_KEYS_TO_SANITIZE)

# Report changes for idempotency depending on methods
nd.result["status"] = nd.status
if sanitize(nd.result["jsondata"], keys_to_sanitize) != nd.previous and method != "GET":
if sanitize(nd.result["jsondata"], ND_REST_KEYS_TO_SANITIZE) != nd.previous and method != "GET":
nd.result["changed"] = True

# Report success
Expand Down

0 comments on commit 676bfe4

Please sign in to comment.