-
Notifications
You must be signed in to change notification settings - Fork 62
test: ensure role gathers the facts it uses by having test clear_facts before include_role #593
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| # Task file: save facts, clear_facts, run linux-system-roles.storage, then restore facts. | ||
| # Include this with include_tasks or import_tasks; ensure tests/library is in module search path. | ||
| # Input: | ||
| # - __sr_tasks_from: tasks_from to run - same as tasks_from in include_role | ||
| # - __sr_public: export private vars from role - same as public in include_role | ||
| # - __sr_failed_when: set to false to ignore role errors - same as failed_when in include_role | ||
| # Output: | ||
| # - ansible_facts: merged saved ansible_facts with ansible_facts modified by the role, if any | ||
| - name: Clear facts | ||
| meta: clear_facts | ||
|
|
||
| # note that you can use failed_when with import_role but not with include_role | ||
| # so this simulates the __sr_failed_when false case | ||
| # Q: Why do we need a separate task to run the role normally? Why not just | ||
| # run the role in the block and rethrow the error in the rescue block? | ||
| # A: Because you cannot rethrow the error in exactly the same way as the role does. | ||
| # It might be possible to exactly reconstruct ansible_failed_result but it's not worth the effort. | ||
| - name: Run the role with __sr_failed_when false | ||
| when: | ||
| - __sr_failed_when is defined | ||
| - not __sr_failed_when | ||
| block: | ||
| - name: Run the role | ||
| include_role: | ||
| name: linux-system-roles.storage | ||
| tasks_from: "{{ __sr_tasks_from | default('main') }}" | ||
| public: "{{ __sr_public | default(false) }}" | ||
| rescue: | ||
| - name: Ignore the failure when __sr_failed_when is false | ||
| debug: | ||
| msg: Ignoring failure when __sr_failed_when is false | ||
|
|
||
| - name: Run the role normally | ||
| include_role: | ||
| name: linux-system-roles.storage | ||
| tasks_from: "{{ __sr_tasks_from | default('main') }}" | ||
| public: "{{ __sr_public | default(false) }}" | ||
| when: __sr_failed_when | d(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Using a block-level
varsforstorage_cryptsetup_servicesprevents it from seeing services gathered byservice_factsin the same blockBecause block-level
varsare evaluated before any tasks in the block run,storage_cryptsetup_servicesis computed once, whenansible_factsstill lacksservices. It becomes[]via theif 'services' in ansible_facts else []guard and is never recomputed afterservice_factspopulatesansible_facts.services, so the latersystemdmasking step sees an empty list and is a no-op on the first run.To have
storage_cryptsetup_servicesuse the newly gathered service facts, either move this expression into aset_factthat runs afterservice_facts, or define it as task-levelvarson thesystemd(or other consuming) tasks so it evaluates afterservice_factshas executed. Otherwise, cryptsetup services will be skipped when service facts weren’t pre-existing.