Skip to content

Commit

Permalink
chore: user return for check_mode for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
rmocanu-ionos committed Aug 27, 2024
1 parent 15fd122 commit d30fc60
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions plugins/module_utils/common_ionos_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ def update_replace_object(self, existing_object, clients):
module.fail_json(msg="{} should be replaced but allow_replace is set to False.".format(self.object_name))

if module.check_mode:
module.exit_json(
**{
'changed': True,
'msg': '{object_name} {object_name_identifier} would be recreated'.format(
object_name=self.object_name, object_name_identifier=obj_identifier,
),
'diff': module_diff,
},
)
return {
'changed': True,
'msg': '{object_name} {object_name_identifier} would be recreated'.format(
object_name=self.object_name, object_name_identifier=obj_identifier,
),
'diff': module_diff,
}

new_object = self._create_object(existing_object, clients).to_dict()
self._remove_object(existing_object, clients)
return {
Expand All @@ -113,15 +112,13 @@ def update_replace_object(self, existing_object, clients):

if self._should_update_object(existing_object, clients):
if module.check_mode:
module.exit_json(
**{
'changed': True,
'msg': '{object_name} {object_name_identifier} would be updated'.format(
object_name=self.object_name, object_name_identifier=obj_identifier,
),
'diff': module_diff,
},
)
return {
'changed': True,
'msg': '{object_name} {object_name_identifier} would be updated'.format(
object_name=self.object_name, object_name_identifier=obj_identifier,
),
'diff': module_diff,
}

# Update
return {
Expand Down Expand Up @@ -152,14 +149,12 @@ def present_object(self, clients):
return self.update_replace_object(existing_object, clients)

if self.module.check_mode:
self.module.exit_json(
**{
'skipped': True,
'msg': '{object_name} {object_name_identifier} would be created'.format(
object_name=self.object_name, object_name_identifier=self._get_object_name(),
)
},
)
return {
'skipped': True,
'msg': '{object_name} {object_name_identifier} would be created'.format(
object_name=self.object_name, object_name_identifier=self._get_object_name(),
)
}

return {
'changed': True,
Expand Down Expand Up @@ -214,14 +209,12 @@ def absent_object(self, clients):
return

if self.module.check_mode:
self.module.exit_json(
**{
'skipped': True,
'msg': '{object_name} {object_name_identifier} would be deleted'.format(
object_name=self.object_name, object_name_identifier=self._get_object_identifier(),
)
},
)
return {
'skipped': True,
'msg': '{object_name} {object_name_identifier} would be deleted'.format(
object_name=self.object_name, object_name_identifier=self._get_object_identifier(),
)
}

self._remove_object(existing_object, clients)

Expand Down

0 comments on commit d30fc60

Please sign in to comment.