-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead #226
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
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 <[email protected]>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the role and its tests/docs to stop using deprecated top-level Ansible fact variables (e.g. ansible_distribution, ansible_default_ipv4) and instead access them via the ansible_facts dict, ensuring compatibility with INJECT_FACTS_AS_VARS=false on newer Ansible versions. Sequence diagram for accessing Ansible facts via ansible_facts with INJECT_FACTS_AS_VARS=falsesequenceDiagram
actor User
participant AnsibleController
participant AnsibleFactsSystem
participant VpnRole
User->>AnsibleController: run ansible_playbook
AnsibleController->>AnsibleFactsSystem: gather_facts
AnsibleFactsSystem-->>AnsibleController: ansible_facts dict
AnsibleController->>VpnRole: execute role tasks with ansible_facts
VpnRole->>VpnRole: compute __vpn_is_rh_distro
Note over VpnRole: __vpn_is_rh_distro = ansible_facts['distribution'] in __vpn_rh_distros
VpnRole->>VpnRole: compute __vpn_is_rh_distro_fedora
Note over VpnRole: __vpn_is_rh_distro_fedora = ansible_facts['distribution'] in __vpn_rh_distros_fedora
VpnRole->>VpnRole: compute __vpn_current_ip
Note over VpnRole: __vpn_current_ip = ansible_facts['default_ipv4'].address | d(ansible_facts['default_ipv6'].address)
VpnRole-->>AnsibleController: tasks complete without using top_level facts
AnsibleController-->>User: playbook run completes without deprecation warnings
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[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
tasks/mesh_conf.yml,ansible_facts['default_ipv4'].addressand the IPv6 equivalent should use dictionary-style access (ansible_facts['default_ipv4']['address']) rather than attribute access to avoid runtime errors, sinceansible_facts['default_ipv4']is a dict, not an object.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `tasks/mesh_conf.yml`, `ansible_facts['default_ipv4'].address` and the IPv6 equivalent should use dictionary-style access (`ansible_facts['default_ipv4']['address']`) rather than attribute access to avoid runtime errors, since `ansible_facts['default_ipv4']` is a dict, not an object.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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 [email protected]
Summary by Sourcery
Update role and documentation to use ansible_facts instead of deprecated fact variables.
Enhancements:
Documentation:
Tests: