refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead#832
Conversation
…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 GuideRefactors the role and its test suite to stop using deprecated top-level Ansible fact variables (e.g. ansible_distribution, ansible_distribution_major_version, ansible_os_family, ansible_python) and instead reference the corresponding keys under ansible_facts, keeping all existing logic and conditionals intact while making the code compatible with INJECT_FACTS_AS_VARS=false in newer Ansible versions. Flow diagram for network provider selection based on ansible_factsflowchart TD
A[Start] --> B[Read ansible_facts_distribution]
B --> C[Read ansible_facts_distribution_major_version]
C --> D{ansible_facts_distribution in __network_rh_distros?}
D -- No --> G[Set network_provider_os_default to nm]
D -- Yes --> E{ansible_facts_distribution_major_version < 7?}
E -- Yes --> F[Set network_provider_os_default to initscripts]
E -- No --> G[Set network_provider_os_default to nm]
F --> H[End]
G --> H[End]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #832 +/- ##
==========================================
+ Coverage 43.11% 43.22% +0.10%
==========================================
Files 12 12
Lines 3124 3123 -1
==========================================
+ Hits 1347 1350 +3
+ Misses 1777 1773 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
[citest] |
|
fixes #829 |
|
qemu tests failing because ipv6 is disabled |
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
Refactor role defaults, tasks, and test playbooks to stop using deprecated top-level Ansible fact variables and instead reference facts via the ansible_facts mapping for compatibility with INJECT_FACTS_AS_VARS=false.
Enhancements:
Tests:
Chores: