Skip to content

Replace injected Ansible fact variables in network_facts and system_packages role#13324

Open
wt wants to merge 1 commit into
kubernetes-sigs:masterfrom
wt:fix_ansible_2.20_fact_inject_warnings
Open

Replace injected Ansible fact variables in network_facts and system_packages role#13324
wt wants to merge 1 commit into
kubernetes-sigs:masterfrom
wt:fix_ansible_2.20_fact_inject_warnings

Conversation

@wt

@wt wt commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

The old way of injecting facts as variables is deprecated. Switching to the new way.

roles updated:

  • network_facts
  • system_packages

/kind bug

Special notes for your reviewer:
Injecting facts as vars is deprecated. See here.

Just so you know, I am using a local branch modified to allow the use of ansible 2.20. These changes should be backward compatible with 2.18/19, which are the currently supported versions of ansible for kubespray.

Does this PR introduce a user-facing change?

NONE

@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 23, 2026
@kubernetes-prow kubernetes-prow Bot requested review from VannTen and mzaian June 23, 2026 07:12
@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 23, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @wt. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@tico88612

Copy link
Copy Markdown
Member

Related #13208

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 23, 2026
@tico88612

Copy link
Copy Markdown
Member

/remove-kind bug
/kind cleanup

@kubernetes-prow kubernetes-prow Bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jun 23, 2026
Comment thread roles/network_facts/tasks/main.yaml Outdated
@tico88612

Copy link
Copy Markdown
Member

/retitle Replace injected Ansible fact variables in network_facts and system_packages role

@kubernetes-prow kubernetes-prow Bot changed the title fix: access facts in supported manner Replace injected Ansible fact variables in network_facts and system_packages role Jun 23, 2026
@wt wt force-pushed the fix_ansible_2.20_fact_inject_warnings branch 4 times, most recently from 72d1e42 to 7a10466 Compare June 23, 2026 10:01
@kubernetes-prow kubernetes-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 23, 2026
@wt wt force-pushed the fix_ansible_2.20_fact_inject_warnings branch from 69bd0c4 to 541bc70 Compare June 23, 2026 10:39
@kubernetes-prow kubernetes-prow Bot removed the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 23, 2026
@wt wt marked this pull request as draft June 23, 2026 10:39
@kubernetes-prow kubernetes-prow Bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 23, 2026
@kubernetes-prow kubernetes-prow Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 24, 2026
@wt wt force-pushed the fix_ansible_2.20_fact_inject_warnings branch from 2adceb3 to f622e71 Compare June 24, 2026 06:39
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 24, 2026
@wt wt force-pushed the fix_ansible_2.20_fact_inject_warnings branch 2 times, most recently from 66efc7e to ad7c8f6 Compare June 24, 2026 07:14
@wt wt marked this pull request as ready for review June 24, 2026 07:19
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 24, 2026
@wt

wt commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Assuming the tests all pass. I think this one is ready to go.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Kubespray’s network_facts and system_packages roles to avoid deprecated “inject facts as vars” usage by switching from injected ansible_* fact variables (e.g., ansible_os_family) to ansible_facts[...] access, in line with Ansible’s porting guidance.

Changes:

  • Replace injected OS/distribution/package-manager fact variables with ansible_facts[...] in system_packages.
  • Update network_facts to gather and reference network facts via ansible_facts instead of injected ansible_default_* variables.
  • Adjust network_facts hostname extraction logic for no_proxy preparation (currently has a functional regression).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
roles/system_packages/vars/main.yml Switch package condition predicates from injected fact vars to ansible_facts[...].
roles/system_packages/tasks/main.yml Use ansible_facts[...] for pkg manager / OS checks and package cache behavior.
roles/network_facts/tasks/main.yaml Use ansible_facts for default IP facts and update fact-gathering filter; modifies no_proxy hostname aggregation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread roles/network_facts/tasks/main.yaml
Comment thread roles/network_facts/tasks/main.yaml

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread roles/network_facts/tasks/main.yaml Outdated
Comment thread roles/network_facts/tasks/main.yaml Outdated
Comment thread roles/network_facts/tasks/main.yaml
@wt wt marked this pull request as draft June 26, 2026 19:21
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 26, 2026
@wt

wt commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

I have converted this back to a draft to experiment with just enabling the inject_facts_as_vars = no in the test config. I want to see how much fallout that causes.

@wt wt force-pushed the fix_ansible_2.20_fact_inject_warnings branch 3 times, most recently from 8c24637 to c7ec84d Compare June 26, 2026 20:18
@wt wt marked this pull request as ready for review June 26, 2026 20:40
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 26, 2026
@kubernetes-prow kubernetes-prow Bot requested a review from guoard June 26, 2026 20:40
The old way of injecting facts as variables is deprecated. Switching to the
new way.

roles updated:
* network_facts
* system_packages
@wt

wt commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Can someone please check this one to see if it's ready for lgtm/approve?

@tico88612 tico88612 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more question, but nit.

otherwise LGTM

filter: "ansible_default_ip*"
when: ansible_default_ipv4 is not defined or ansible_default_ipv6 is not defined
filter: "default_ip*"
when: "ansible_facts is not defined or 'default_ipv4' not in ansible_facts or 'default_ipv6' not in ansible_facts"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need ansible_facts is not defined here?
Under what circumstances would ansible_facts be undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants