-
Notifications
You must be signed in to change notification settings - Fork 17
refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead #253
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
+16
−16
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 all use of top-level Ansible fact variables to the supported ansible_facts[...] lookups so the role and its tests work with INJECT_FACTS_AS_VARS=false and upcoming Ansible 2.24 changes. Flow diagram for insights registration and unregistration using ansible_factsflowchart TD
start["Start role execution with gathered ansible_facts"]
start --> distro_check{"ansible_facts['distribution'] == RedHat"}
distro_check -->|No| end_no_rh["Skip insights registration and unregistration tasks"]
distro_check -->|Yes| state_check_unreg{"rhc_insights.state or rhc_state indicate unregistration"}
state_check_unreg -->|Yes| do_unreg["Include task file insights-client-unregistration.yml"]
state_check_unreg -->|No| state_check_reg{"rhc_insights.state and rhc_state indicate registration"}
state_check_reg -->|Yes| do_reg["Include task file insights-client.yml"]
state_check_reg -->|No| no_action["No registration or unregistration actions"]
do_unreg --> end_node["End role execution"]
do_reg --> end_node
no_action --> end_node
end_no_rh --> end_node
Flow diagram for distro-specific vars and remediation config using ansible_factsflowchart TD
start["Start variable evaluation"] --> major_ver_check{"ansible_facts['distribution_major_version'] >= 10"}
major_ver_check -->|Yes| set_ygg["Set __rhc_yggdrasil_systemd_service = 'yggdrasil'"]
major_ver_check -->|No| set_rhcd["Set __rhc_yggdrasil_systemd_service = 'rhcd'"]
set_ygg --> distro_check{"ansible_facts['distribution'] in __rhc_rh_distros"}
set_rhcd --> distro_check
distro_check -->|Yes| mark_rh["Set __rhc_is_rh_distro = true"]
distro_check -->|No| mark_not_rh["Set __rhc_is_rh_distro = false"]
distro_fedora_check{"ansible_facts['distribution'] in __rhc_rh_distros_fedora"}
mark_rh --> distro_fedora_check
mark_not_rh --> distro_fedora_check
distro_fedora_check -->|Yes| mark_rh_fedora["Set __rhc_is_rh_distro_fedora = true"]
distro_fedora_check -->|No| mark_not_rh_fedora["Set __rhc_is_rh_distro_fedora = false"]
mark_rh_fedora --> ver_check["Check remediation condition: ansible_facts['distribution_version'] >= 8.4"]
mark_not_rh_fedora --> ver_check
ver_check -->|Yes| cfg_remediation["Execute remediation configuration block"]
ver_check -->|No| skip_remediation["Skip remediation configuration"]
cfg_remediation --> end_node["End variable and remediation evaluation"]
skip_remediation --> end_node
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Contributor
Author
|
[citest] |
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
Enhancements: