Repository navigation
Gate the generated Ansible collection on ansible-lint in CI #15184
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
Merged
jan-cerny
merged 5 commits into
ComplianceAsCode:master
from
ggbecker:cert-ansible-lint-ci-gate
Oct 23, 2026
+106
−8
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09ea1be
Tighten the Ansible role lint gate for certification rules
ggbecker eb3b4dc
Gate Ansible collection on command-instead-of-module in CI
ggbecker 8cd829b
Address collection gate review feedback
ggbecker f68dafc
Fix yamllint brackets spacing in gate-lint-ansible-roles.yaml
ggbecker 4f875c1
Set owner: root on the gpgcheck ini_file tasks
ggbecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/bin/bash | ||
| # Test script: build Ansible roles then generate an Ansible collection. | ||
| # | ||
| # Usage: utils/test_ansible_collection.sh [OUTPUT_DIR] [PRODUCT] [TARGET] | ||
| # OUTPUT_DIR destination for the generated collection (default: /tmp/test-collection) | ||
| # PRODUCT ComplianceAsCode product to build roles for (default: rhel9) | ||
| # TARGET Collection registry target: galaxy (namespace redhatofficial) or | ||
| # hub (namespace redhat) (default: galaxy) | ||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SSG_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" | ||
| OUTPUT_DIR="${1:-/tmp/test-collection}" | ||
| PRODUCT="${2:-rhel9}" | ||
| TARGET="${3:-galaxy}" | ||
| BUILD_DIR="${SSG_ROOT}/build" | ||
|
|
||
| echo "=== Step 1: Configure and build ${PRODUCT} with Ansible roles ===" | ||
| cd "${SSG_ROOT}" | ||
|
|
||
| # Use build_product only for the cmake configuration step; the --datastream flag | ||
| # limits what gets built so we follow up with an explicit roles target below. | ||
| ADDITIONAL_CMAKE_OPTIONS="-DSSG_ANSIBLE_ROLES_ENABLED=TRUE" \ | ||
| ./build_product "${PRODUCT}" --datastream | ||
|
|
||
| echo "" | ||
| echo "=== Step 2: Build Ansible roles target ===" | ||
| cd "${BUILD_DIR}" | ||
| ninja "generate-$(echo "${PRODUCT}" | tr '[:upper:]' '[:lower:]')-ansible-roles" | ||
| cd "${SSG_ROOT}" | ||
|
|
||
| echo "" | ||
| echo "=== Step 3: Generate Ansible collection ===" | ||
| rm -rf "${OUTPUT_DIR}" | ||
| python3 utils/ansible_roles_to_collection.py \ | ||
| --roles-dir "${BUILD_DIR}/ansible_roles" \ | ||
| --output-dir "${OUTPUT_DIR}" \ | ||
| --target "${TARGET}" \ | ||
| --build | ||
|
|
||
| echo "" | ||
| echo "=== Step 4: Verify output ===" | ||
| # --target selects the namespace (galaxy -> redhatofficial, hub -> redhat); there | ||
| # is no standalone --namespace flag anymore. | ||
| case "${TARGET}" in | ||
| hub) NAMESPACE="redhat" ;; | ||
| galaxy|*) NAMESPACE="redhatofficial" ;; | ||
| esac | ||
| COLLECTION_DIR="${OUTPUT_DIR}/ansible_collections/${NAMESPACE}/rhel_hardening_roles" | ||
|
|
||
| echo "--- Vendored modules ---" | ||
| ls "${COLLECTION_DIR}/plugins/modules/" | ||
|
|
||
| echo "" | ||
| echo "--- FQCN rewrite check ---" | ||
| STATUS=0 | ||
| if grep -rq "community\.general\.\|ansible\.posix\." "${COLLECTION_DIR}/roles/" 2>/dev/null; then | ||
| echo "FAIL: unrewritten FQCNs found:" | ||
| grep -rn "community\.general\.\|ansible\.posix\." "${COLLECTION_DIR}/roles/" | ||
| STATUS=1 | ||
| else | ||
| echo "OK: no unrewritten FQCNs in roles" | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "--- galaxy.yml ---" | ||
| python3 -c " | ||
| import yaml | ||
| d = yaml.safe_load(open('${COLLECTION_DIR}/galaxy.yml')) | ||
| print(' namespace:', d['namespace']) | ||
| print(' name: ', d['name']) | ||
| print(' version: ', d['version']) | ||
| " | ||
|
|
||
| echo "" | ||
| echo "=== Done ===" | ||
| echo "Artifact: $(ls "${OUTPUT_DIR}"/"${NAMESPACE}"-rhel_hardening_roles-*.tar.gz 2>/dev/null || echo 'not found')" | ||
| exit "${STATUS}" | ||
Oops, something went wrong.
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.
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.
Should it exit with 1 and/or save the exit code to exit with 1? It seems that it will print FAIL but finish successfully.
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.
Should be fixed by:
Make utils/test_ansible_collection.sh return a non-zero exit status when the
FQCN rewrite check finds unrewritten references, instead of printing FAIL and
finishing successfully.