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

Validate task attributes with first finalized attrs after loop #80476

Merged
merged 5 commits into from Apr 13, 2023

Conversation

s-hertel
Copy link
Contributor

SUMMARY

Fixing post validating the task itself when getting loop results. Previously we validated a copy of the task per loop item, but never finalized the overall task the strategy uses later.

This is an alternative to the fix in #80051, without breaking inheritance. Omit still does not work as intended, as with many FA (it's a truthy string), but this is a more general problem we should address.

Supersedes #80382 as a stop-gap before #80394 to unbreak inheritance.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

TE

@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. affects_2.16 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. labels Apr 11, 2023
@s-hertel s-hertel force-pushed the fix-post-validating-tasks-with-loops branch from 71a25e0 to 2b46220 Compare April 11, 2023 12:59
@s-hertel s-hertel force-pushed the fix-post-validating-tasks-with-loops branch from 2b46220 to f74f3bd Compare April 11, 2023 13:27
@s-hertel s-hertel marked this pull request as ready for review April 11, 2023 14:44
@ansibot ansibot removed the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Apr 11, 2023
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Apr 11, 2023
once there's a way to post validate only certain fields, we can use self._task.post_validate() at the end instead of repopulating task fields from the iteration
@s-hertel s-hertel requested a review from bcoca April 11, 2023 16:50
…e but needs to behave like ignore_errors rather than just using the last loop

single out run_once from attrs to limit scope of the change
self._task.no_log = no_log
# NOTE: run_once cannot contain loop vars because it's templated earlier also
# This is saving the post-validated field from the last loop so the strategy can use the templated value post task execution
self._task.run_once = task_fields.get('run_once')
Copy link
Contributor Author

@s-hertel s-hertel Apr 12, 2023

Choose a reason for hiding this comment

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

I was worried self._task.from_attrs(task_fields) might cause issues, so I tried to identify all the FieldAttributes potentially affected by this issue. I believe it's limited to the fields action, run_once, ignore_unreachable, ignore_errors, loop, and no_log since these may be used after the looped task is executed.

  • no_log is fine, because it's set just above this change
  • loop is fine because empty loops == skipped task and the codepath with the issue (template string is always truthy) doesn't occur
  • ignore_errors is fine because the value for the Task is set to False if any of the individual items are False

So I fixed ignore_unreachable using the same pattern as ignore_errors, and limited this to just set run_once and action.

@s-hertel s-hertel merged commit bd6feeb into ansible:devel Apr 13, 2023
86 checks passed
s-hertel added a commit to s-hertel/ansible that referenced this pull request Apr 13, 2023
…le#80476)

* Validate task attributes `run_once` and `action` with finalized attrs after individual loop results

* Validate task attribute `ignore_unreachable` using individual loop results

Once there's a way to post validate only certain fields, we can use self._task.post_validate() instead

This replaces the fix introduced in ansible#80051.

(cherry picked from commit bd6feeb)
s-hertel added a commit to s-hertel/ansible that referenced this pull request Apr 13, 2023
…le#80476)

* Validate task attributes `run_once` and `action` with finalized attrs after individual loop results

* Validate task attribute `ignore_unreachable` using individual loop results

Once there's a way to post validate only certain fields, we can use self._task.post_validate() instead

This replaces the fix introduced in ansible#80051.

(cherry picked from commit bd6feeb)
sivel pushed a commit that referenced this pull request Apr 17, 2023
… (#80517)

* Validate task attributes `run_once` and `action` with finalized attrs after individual loop results

* Validate task attribute `ignore_unreachable` using individual loop results

Once there's a way to post validate only certain fields, we can use self._task.post_validate() instead

This replaces the fix introduced in #80051.

(cherry picked from commit bd6feeb)
@ansible ansible locked and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.16 bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants