-
Notifications
You must be signed in to change notification settings - Fork 6
refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead #122
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
Conversation
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
…stead Ansible 2.20 has deprecated the use of Ansible facts as variables. For example, `ansible_distribution` is now deprecated in favor of `ansible_facts["distribution"]`. This is due to making the default setting `INJECT_FACTS_AS_VARS=false`. For now, this will create WARNING messages, but in Ansible 2.24 it will be an error. See https://docs.ansible.com/projects/ansible/latest/porting_guides/porting_guide_core_2.20.html#inject-facts-as-vars Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors Ansible variable usage to rely on ansible_facts lookups instead of deprecated implicit fact variables, updating both role defaults and associated test fixtures/comments. Flow diagram for using ansible_facts when INJECT_FACTS_AS_VARS is falseflowchart TD
Start["Playbook runs role"] --> GatherFacts["Ansible gathers facts"]
GatherFacts --> CheckSetting{"INJECT_FACTS_AS_VARS is true?"}
CheckSetting -->|"Yes"| DeprecatedPath["Deprecated: tasks may use ansible_distribution"]
CheckSetting -->|"No"| FactsMap["Facts available only via ansible_facts map"]
FactsMap --> GetDistribution["Use ansible_facts['distribution']"]
GetDistribution --> CheckRHDistro{"ansible_facts['distribution'] in __pam_pwd_rh_distros?"}
GetDistribution --> CheckRHDistroFedora{"ansible_facts['distribution'] in __pam_pwd_rh_distros_fedora?"}
CheckRHDistro --> SetVarRHDistro["Set __pam_pwd_is_rh_distro"]
CheckRHDistroFedora --> SetVarRHDistroFedora["Set __pam_pwd_is_rh_distro_fedora"]
SetVarRHDistro --> RoleTasks["Role tasks use new boolean vars"]
SetVarRHDistroFedora --> RoleTasks
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
Author
|
[citest] |
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.
Hey - I've left some high level feedback:
- In
tests/tests_include_vars_from_parent.yml, the updated comments referenceansible_facts[...]while thevarfilesexpression still usesfacts[...]; consider aligning these to avoid confusion about which variable set is actually used. - Where you now access
ansible_facts['distribution'], consider using a safer pattern likeansible_facts.get('distribution', '')(or adefaultfilter) if this role may run with fact gathering disabled to avoid undefined-variable issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `tests/tests_include_vars_from_parent.yml`, the updated comments reference `ansible_facts[...]` while the `varfiles` expression still uses `facts[...]`; consider aligning these to avoid confusion about which variable set is actually used.
- Where you now access `ansible_facts['distribution']`, consider using a safer pattern like `ansible_facts.get('distribution', '')` (or a `default` filter) if this role may run with fact gathering disabled to avoid undefined-variable issues.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ansible 2.20 has deprecated the use of Ansible facts as variables. For
example,
ansible_distributionis now deprecated in favor ofansible_facts["distribution"]. This is due to making the defaultsetting
INJECT_FACTS_AS_VARS=false. For now, this will create WARNINGmessages, but in Ansible 2.24 it will be an error.
See https://docs.ansible.com/projects/ansible/latest/porting_guides/porting_guide_core_2.20.html#inject-facts-as-vars
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Update Ansible role variables and tests to use ansible_facts-based access instead of deprecated top-level fact variables.
Enhancements:
Tests: