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

Add diff mode support to ansible modules #15118

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions awx_collection/plugins/module_utils/controller_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ def delete_if_needed(self, existing_item, item_type=None, on_delete=None, auto_e
except KeyError as ke:
self.fail_json(msg="Unable to process delete of item due to missing data {0}".format(ke))

if self._diff:
self.json_output['diff'] = dict(before=existing_item, after={})

response = self.delete_endpoint(item_url)

if response['status_code'] in [202, 204]:
Expand Down Expand Up @@ -810,6 +813,9 @@ def create_if_needed(self, existing_item, new_item, endpoint, on_create=None, au
# We will pull the item_name out from the new_item, if it exists
item_name = self.get_item_name(new_item, allow_unknown=True)

if self._diff:
self.json_output['diff'] = dict(before={}, after=new_item)

response = self.post_endpoint(endpoint, **{'data': new_item})

# 200 is response from approval node creation on tower 3.7.3 or awx 15.0.0 or earlier.
Expand Down Expand Up @@ -944,6 +950,8 @@ def update_if_needed(self, existing_item, new_item, item_type=None, on_update=No
# If we decided the item needs to be updated, update it
self.json_output['id'] = item_id
if needs_patch:
if self._diff:
self.json_output['diff'] = dict(before={key: existing_item[key] for key in new_item.keys()}, after=new_item)
response = self.patch_endpoint(item_url, **{'data': new_item})
if response['status_code'] == 200:
# compare apples-to-apples, old API data to new API data
Expand Down