Skip to content

[cifmw_helpers] Fix non-deterministic parameter-dir include order - #4142

Merged
openshift-merge-bot[bot] merged 1 commit into
mainfrom
fix-include-dir-sort-order
Aug 26, 2026
Merged

[cifmw_helpers] Fix non-deterministic parameter-dir include order#4142
openshift-merge-bot[bot] merged 1 commit into
mainfrom
fix-include-dir-sort-order

Conversation

@imatza-rh

@imatza-rh imatza-rh commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

include_dir.yml finds YAML files in a directory (e.g.
artifacts/parameters) via ansible.builtin.find, then loops over them
calling include_vars. find() never sorts (verified in the installed
find.py: os.walk(), no sorted() call), so if two files define the
same key, which wins is filesystem-order dependent.

Same defect shape as PR #4138
(OSPNW-1694): there,
edpm_fips_mode: check was silently lost to a same-directory default.
That case was a live, reproduced failure. This one is preventative --
current artifacts/parameters writers (openshift_login, cifmw_nfs,
install_yamls) each use a distinct prefix, so no active collision
exists today. This closes the same latent class before a future writer
hits it. Kept as a separate PR since it's a different role/file and
#4138 has its own unresolved CI failure to isolate.

Fix

sort(attribute='path') on the include loop, so order is deterministic.

Verification

  • Confirmed no sorted()/.sort() in find.py's source.
  • Fetched genuine pre-fix code via git show origin/main:... and ran it
    through real ansible-playbook against colliding-key fixtures --
    fix reliably makes the lexically-last file win.
  • ansible-lint passes.
  • Existing cifmw_helpers molecule test for include_dir.yml only uses
    one fixture file, so it's a no-op there (no regression, but also no
    CI coverage of the multi-file case this fixes).

Related-Issue: #OSPNW-1694

include_dir.yml loads YAML files from a directory (e.g.
artifacts/parameters, populated by many independent roles/hooks) via
ansible.builtin.find, then loops over the results calling include_vars
per file. find() does not guarantee sorted results (confirmed in the
installed find.py: it walks with os.walk() and never sorts), so if two
files in the same directory ever define the same variable, which one
wins is filesystem-order dependent instead of deterministic.

This is the same defect shape already fixed in ci_gen_kustomize_values'
generate_values.yml (PR #4138, OSPNW-1694): a user-provided
edpm_fips_mode: check override was silently discarded by a
same-directory default because the combine loop's find() order wasn't
sorted. That case had a live, reproduced failure; this one is
preventative, not a confirmed active flake -- current writers into
artifacts/parameters use distinct per-role variable prefixes (e.g.
cifmw_openshift_*, cifmw_nfs_*), so no key collision was found in
today's usage. It closes off the same latent class of bug for any
future writer into that shared directory.

Add an explicit sort(attribute='path') so include order is always
deterministic (lexical path order) rather than filesystem-dependent.
Verified against a real ansible-playbook run (not just static
reasoning): with two files defining the same key, the fix reliably
lets the lexically-last file win regardless of the underlying find()
order, matching the intended override-precedence convention.

Related-Issue: #OSPNW-1694
Signed-off-by: Itay Matza <imatza@redhat.com>
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Make parameter directory includes deterministic

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Sort discovered YAML files by path before including variables.
• Resolve conflicting keys deterministically instead of relying on filesystem traversal order.
Diagram

graph TD
  A["Parameter Directory"] --> B["Find YAML Files"] --> C["Sort by Path"] --> D["Include Variables"] --> E["Deterministic Precedence"]
Loading
High-Level Assessment

The explicit path sort is the best approach because it fixes nondeterminism at the consumption point with minimal scope. Relying on filesystem order is unsafe, while replacing the existing include workflow would be unnecessary given its support for templated YAML values.

Files changed (1) +5 / -1

Bug fix (1) +5 / -1
include_dir.ymlSort YAML includes by lexical path +5/-1

Sort YAML includes by lexical path

• Sorts files returned by 'ansible.builtin.find' before invoking the include task. This guarantees stable variable override precedence when multiple files define the same key.

roles/cifmw_helpers/tasks/include_dir.yml

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@nemarjan nemarjan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci

openshift-ci Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nemarjan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 3bb07bd into main Aug 26, 2026
12 checks passed
@openshift-merge-bot
openshift-merge-bot Bot deleted the fix-include-dir-sort-order branch August 26, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants