Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: return rule id for existing rule #665

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions plugins/modules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def __init__(self, module):

if self.rule_id:
# Get the current rule from the API and set some parameters
(self.current, self.state) = self._get_current()
(self.current, self.state, self.result) = self._get_current()
if self.state == "present":
self._changed_items = self._detect_changes()

Expand All @@ -560,7 +560,7 @@ def _verify_location(self):
neighbour_id = self.params.get("rule", {}).get("location", {}).get("neighbour")

if neighbour_id:
(neighbour, state) = self._get_rule_by_id(neighbour_id)
(neighbour, state, result) = self._get_rule_by_id(neighbour_id)

if state == "absent":
self.module.warn(
Expand Down Expand Up @@ -723,7 +723,7 @@ def _get_rule_by_id(self, rule_id):
if key in CURRENT_RULE_KEYS
}

return (current, state)
return (current, state, result)

def _get_current(self):
return self._get_rule_by_id(self.rule_id)
Expand All @@ -738,6 +738,9 @@ def _check_output(self, mode):
changed=True,
)

def get_retrieve_result(self):
return self.result

def needs_update(self):
return len(self._changed_items) > 0

Expand Down Expand Up @@ -951,9 +954,11 @@ def run_module():
if current_rule.needs_update():
result = current_rule.edit()
else:
result = current_rule.get_retrieve_result()
result = result._replace(
msg="Rule already exists with the desired parameters."
)

elif rule_id:
# There is no rule with the given rule_id
result = result._replace(
Expand Down