fix: ensure idempotence by writing settings in sorted order#295
Merged
richm merged 1 commit intolinux-system-roles:mainfrom Feb 25, 2026
Merged
fix: ensure idempotence by writing settings in sorted order#295richm merged 1 commit intolinux-system-roles:mainfrom
richm merged 1 commit intolinux-system-roles:mainfrom
Conversation
Cause: On EL7, the underlying module uses an unordered dict, so the order of the settings being written can change between role invocations. Consequence: The role may report changed when nothing actually changed except the order. Fix: The settings are sorted before being written so that the order is consistent. Result: The role does not report changed when nothing has changed. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures idempotent generation of kernel settings by iterating over settings keys in sorted order before rendering, preventing spurious changes due to dictionary ordering differences on EL7. Sequence diagram for idempotent kernel_settings template renderingsequenceDiagram
actor User
participant AnsibleController
participant TemplateEngine
participant ManagedNode
User->>AnsibleController: Run kernel_settings role
AnsibleController->>TemplateEngine: Render kernel_settings.j2 with settings
TemplateEngine->>TemplateEngine: Extract settings keys
TemplateEngine->>TemplateEngine: Sort keys
loop For each sorted key
TemplateEngine->>TemplateEngine: Look up val = settings[key]
alt val.state is absent
TemplateEngine->>TemplateEngine: Skip writing this setting
else val.state is not absent
TemplateEngine->>TemplateEngine: Write line "key = val" in INI section
end
end
TemplateEngine-->>AnsibleController: Rendered kernel_settings content
AnsibleController->>ManagedNode: Compare and write file if changed
ManagedNode-->>AnsibleController: No change if only order differed
AnsibleController-->>User: Report idempotent result (changed only on real change)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Instead of iterating over
settings.keys() | sortand then indexing back into the dict, consider usingfor key, val in settings | dictsortto get a stable, sorted key order in a more idiomatic and readable way.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of iterating over `settings.keys() | sort` and then indexing back into the dict, consider using `for key, val in settings | dictsort` to get a stable, sorted key order in a more idiomatic and readable way.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Collaborator
Author
|
[citest] |
spetrosi
approved these changes
Feb 25, 2026
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
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.
Cause: On EL7, the underlying module uses an unordered dict, so the order of the settings being
written can change between role invocations.
Consequence: The role may report changed when nothing actually changed except the order.
Fix: The settings are sorted before being written so that the order is consistent.
Result: The role does not report changed when nothing has changed.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Bug Fixes: