Add build-time test for ansible variable conflicts#14347
Draft
ggbecker wants to merge 1 commit intoComplianceAsCode:masterfrom
Draft
Add build-time test for ansible variable conflicts#14347ggbecker wants to merge 1 commit intoComplianceAsCode:masterfrom
ggbecker wants to merge 1 commit intoComplianceAsCode:masterfrom
Conversation
This commit adds a new CTest that checks rendered ansible files for variable naming conflicts between registered variables and rule IDs. The problem occurs when ansible remediations register a variable with the same name as a rule ID. For example, if rule 'selinux_state' uses 'register: selinux_state', this creates a conflict with the 'selinux_state' boolean control variable used in when conditions like 'when: selinux_state | bool'. This causes the task to be skipped since the variable shadows the control variable, preventing proper execution. The test checks two locations in the build directory: 1. build/<product>/fixes/ansible/ - Individual rule remediations after template expansion 2. build/ansible/<product>-playbook-*.yml - Per-profile playbooks with fully rendered content The test runs for each product during the build and will fail if any registered variable name matches any rule ID in the system, ensuring that such conflicts are caught early in development. This is integrated into the cmake build system as a new test target 'ansible-variable-conflicts-<product>' that runs automatically during ctest execution and is labeled as a 'quick' test.
|
Skipping CI for Draft Pull Request. |
ATEX Test ResultsTest artifacts have been submitted to Testing Farm. Results: View Test Results This comment was automatically generated by the ATEX workflow. |
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.
Description:
The problem occurs when ansible remediations register a variable with the same name as a rule ID. For example, if rule 'selinux_state' uses 'register: selinux_state', this creates a conflict with the 'selinux_state' boolean control variable used in when conditions like 'when: selinux_state | bool'. This causes the task to be skipped since the variable shadows the control variable, preventing proper execution.
The test checks two locations in the build directory:
The test runs for each product during the build and will fail if any registered variable name matches any rule ID in the system, ensuring that such conflicts are caught early in development.
This is integrated into the cmake build system as a new test target 'ansible-variable-conflicts-' that runs automatically during ctest execution and is labeled as a 'quick' test.
Rationale:
Review Hints:
Concerns
The test takes about 17 seconds to run on my machine for a single product, I would introduce a lot of overhead to the CTest execution. So I don't know if it would make sense to introduce such a test. The
selinux_statewas the only case that ever happened.If we have an easy way to integrate this into the build system as a build step, maybe it wouldn't be so inefficient. Please share your suggestions.
Related to: #14346