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 --diff to produce output when creating a new file #57744

Merged
merged 2 commits into from Jun 12, 2019

Conversation

mkrizek
Copy link
Contributor

@mkrizek mkrizek commented Jun 12, 2019

SUMMARY

#51350 removed apending state: absent for missing files in the module's result. However _get_diff_data method was specifically checking for absent in the result. This changes that to check for missing state key instead.

This needs to be backported to 2.8 if merged.

Fixes #57618

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/plugins/action/__init__.py

@mkrizek mkrizek requested review from bcoca and samdoran June 12, 2019 10:25
@ansibot
Copy link
Contributor

ansibot commented Jun 12, 2019

cc @ptux
click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. files Files category needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 12, 2019
@mkrizek mkrizek requested a review from s-hertel June 12, 2019 10:29
@@ -1104,7 +1104,7 @@ def _get_diff_data(self, destination, source, task_vars, source_file=True):

if not peek_result.get('failed', False) or peek_result.get('rc', 0) == 0:

if peek_result.get('state') == 'absent':
if peek_result.get('state') is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would do both in ('absent', None) as there are cases in which 'absent' would be a correct return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are. peek_result is a result of the file module being executed with _diff_peek=True which just checks if the file is binary and calls exit_json. From there add_path_info is only method that modifies state in the result and no longer sets absent.

Having said that doing in ('absent', None) might be more defensive, so I'd be +1 for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also have to take into account actions that have 'remote_src=true' as they might not rely on peek

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jun 12, 2019
@mkrizek mkrizek requested a review from bcoca June 12, 2019 14:52
@bcoca bcoca merged commit 1fa7bfc into ansible:devel Jun 12, 2019
@mkrizek mkrizek deleted the issue-57618 branch June 12, 2019 15:07
mkrizek added a commit to mkrizek/ansible that referenced this pull request Jun 12, 2019
* Fix --diff to produce output when creating a new file

Fixes ansible#57618

* Make the check more defensive

(cherry picked from commit 1fa7bfc)
abadger pushed a commit that referenced this pull request Jun 15, 2019
* Fix --diff to produce output when creating a new file

Fixes #57618

* Make the check more defensive

(cherry picked from commit 1fa7bfc)
agowa pushed a commit to agowa/ansible-1 that referenced this pull request Jun 30, 2019
* Fix --diff to produce output when creating a new file

Fixes ansible#57618

* Make the check more defensive
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. files Files category support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: --diff does not produce output when template creates new file
4 participants