Skip to content

feat: Add argument spec validation to Image_builder role - #5

Open
DonatSzabo wants to merge 3 commits into
linux-system-roles:mainfrom
DonatSzabo:argument_spec_implementation-dszabo
Open

feat: Add argument spec validation to Image_builder role#5
DonatSzabo wants to merge 3 commits into
linux-system-roles:mainfrom
DonatSzabo:argument_spec_implementation-dszabo

Conversation

@DonatSzabo

@DonatSzabo DonatSzabo commented Aug 11, 2026

Copy link
Copy Markdown

Enhancement: Added argument spec validation to image builder role. Also added separate value assertion and wrote tests for both methods.

Reason: Because it is a good addition to the linux-system-roles project.

Result: Successfully added it and prepared tests for it. I used AI during this implementation.

Issue Tracker Tickets (Jira or BZ if any): linux-system-roles/postfix#206 https://redhat.atlassian.net/browse/RHELMISC-16008

Summary by CodeRabbit

  • New Features

    • Added configurable package tiers and daemon backend selection for Image Builder.
    • Added automatic daemon detection when no backend is specified.
    • Added validation with clear errors for unsupported package or daemon values.
  • Documentation

    • Updated usage guidance, supported package tiers, daemon behavior, and distribution/version mappings.
  • Tests

    • Added coverage for invalid package and daemon inputs.
  • Chores

    • Added repository ignore rules and licensing metadata.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The role now defines public ib_daemon settings, documents package tiers and daemon detection, validates ib_packages, and adds invalid-input tests. Test role directories link to the role implementation.

Changes

Image Builder validation

Layer / File(s) Summary
Public input contract
defaults/main.yml, meta/argument_specs.yml, README.md
The role adds nullable ib_daemon configuration, defines argument specifications, and documents package tiers, daemon detection, and supported distributions.
Role validation and daemon selection
tasks/main.yml, tasks/assert_role_vars.yml
The role validates ib_packages and initializes daemon selection when ib_daemon is none.
Validation test wiring
tests/roles/linux-system-roles.image_builder/*, tests/tests_invalid_input.yml, tox.ini, .gitignore
The test role links to implementation directories. Invalid-input tests cover daemon and package validation. Tox and ignore settings support the test setup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding argument specification validation to the Image Builder role.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tasks/assert_role_vars.yml`:
- Around line 6-7: Update the ib_packages validation assertion to require every
item in list-valued ib_packages to be a string, while preserving validation of
scalar package names against __ib_package_types. Add a regression test covering
lists containing non-string values such as 123 or {} and ensure those inputs are
rejected.

In `@tests/tests_invalid_input.yml`:
- Around line 7-10: Update both ansible_version.full gates in
tests/tests_invalid_input.yml to require version 2.11 or newer, preserving the
invalid-input validation flow. Document the ansible-core 2.11 requirement in
README.md at the referenced location.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe9fbdf6-7986-483f-8a2e-004de78f143e

📥 Commits

Reviewing files that changed from the base of the PR and between 374262a and 0e666c6.

📒 Files selected for processing (13)
  • .gitignore
  • README.md
  • defaults/main.yml
  • meta/argument_specs.yml
  • tasks/assert_role_vars.yml
  • tasks/main.yml
  • tests/roles/linux-system-roles.image_builder/defaults
  • tests/roles/linux-system-roles.image_builder/handlers
  • tests/roles/linux-system-roles.image_builder/meta
  • tests/roles/linux-system-roles.image_builder/tasks
  • tests/roles/linux-system-roles.image_builder/vars
  • tests/tests_invalid_input.yml
  • tox.ini

Comment on lines +6 to +7
- ib_packages is string and ib_packages in __ib_package_types
or ib_packages is not string and ib_packages | type_debug == 'list'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- candidate files ---'
git ls-files | grep -E '(^|/)(tasks/assert_role_vars\.yml|meta/argument_specs\.yml|tests?/|molecule/)' | head -200

printf '%s\n' '--- assertion file ---'
if [ -f tasks/assert_role_vars.yml ]; then
  nl -ba tasks/assert_role_vars.yml | sed -n '1,140p'
fi

printf '%s\n' '--- argument specifications and references ---'
rg -n -C 4 'ib_packages|__ib_package_types|assert_role_vars' . \
  -g '!*.md' -g '!*.json' -g '!*.lock' | head -300

Repository: linux-system-roles/image_builder

Length of output: 14209


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- assertion task ---'
awk '{printf "%5d  %s\n", NR, $0}' tasks/assert_role_vars.yml

printf '%s\n' '--- argument specification ---'
awk '{printf "%5d  %s\n", NR, $0}' meta/argument_specs.yml

printf '%s\n' '--- invalid-input tests ---'
awk '{printf "%5d  %s\n", NR, $0}' tests/tests_invalid_input.yml

printf '%s\n' '--- package task consumers ---'
for f in tasks/setup-yum.yml tasks/setup-dnf.yml tasks/setup-default.yml tasks/main.yml; do
  printf '%s\n' "--- $f ---"
  awk '{printf "%5d  %s\n", NR, $0}' "$f"
done

printf '%s\n' '--- available local runtimes/modules ---'
command -v ansible-playbook || true
python3 - <<'PY'
try:
    import ansible
    print("ansible python module:", ansible.__version__)
except Exception as exc:
    print("ansible python module: unavailable:", type(exc).__name__)
PY

Repository: linux-system-roles/image_builder

Length of output: 7387


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
def ansible_like_type_debug(value):
    if isinstance(value, bool):
        return "bool"
    if isinstance(value, str):
        return "str"
    if isinstance(value, list):
        return "list"
    if isinstance(value, dict):
        return "dict"
    if isinstance(value, int):
        return "int"
    if value is None:
        return "NoneType"
    return type(value).__name__

def accepts(value, package_types=("minimal", "default", "full")):
    is_string = isinstance(value, str)
    return (
        (is_string and value in package_types)
        or (not is_string and ansible_like_type_debug(value) == "list")
    )

cases = {
    "minimal": "minimal",
    "unknown tier": "not_a_valid_tier",
    "integer": 123,
    "list of strings": ["vim", "git"],
    "list with integer": [123],
    "list with mapping": [{}],
    "empty list": [],
}
for label, value in cases.items():
    print(f"{label}: accepted={accepts(value)} type_debug={ansible_like_type_debug(value)}")
PY

printf '%s\n' '--- all ib_packages references and list-oriented tests ---'
rg -n -C 3 'ib_packages' . -g '!*.md' -g '!*.json' -g '!*.lock' | head -400

Repository: linux-system-roles/image_builder

Length of output: 12593


Validate each explicit package name.

The list branch checks only the outer type, so [123] and [{}] pass. meta/argument_specs.yml uses type: raw, so it performs no element validation. Reject non-string list items and add a regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tasks/assert_role_vars.yml` around lines 6 - 7, Update the ib_packages
validation assertion to require every item in list-valued ib_packages to be a
string, while preserving validation of scalar package names against
__ib_package_types. Add a regression test covering lists containing non-string
values such as 123 or {} and ensure those inputs are rejected.

Source: MCP tools

Comment on lines +7 to +10
# Role argument validation requires Ansible 2.10+; skipped on older versions.

- name: Argument specs reject invalid ib_daemon
when: ansible_version.full is version('2.10', '>=')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What ansible-core version introduced role argument specifications and the include_role rolespec_validate option?

💡 Result:

Role argument specifications and the include_role rolespec_validate option were both introduced in ansible-core 2.11 [1][2]. This functionality allows users to define an argument specification in a role's meta/argument_specs.yml file [1][3]. When enabled via the rolespec_validate option in an include_role task, Ansible will validate the parameters provided to the role against this specification, causing the role to fail execution if the parameters do not conform [1][2]. Documentation also notes that the ansible.builtin.validate_argument_spec module, which is used to validate these role arguments, was introduced in the same version [4][5].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- tests/tests_invalid_input.yml ---'
cat -n tests/tests_invalid_input.yml | sed -n '1,80p'

printf '%s\n' '--- README.md ---'
cat -n README.md | sed -n '1,35p'

printf '%s\n' '--- argument-spec and validation references ---'
rg -n -C 3 'argument_specs|rolespec_validate|rescue|invalid ib_daemon|ansible_version' . \
  -g '!*.pyc' -g '!node_modules' -g '!dist' -g '!build'

Repository: linux-system-roles/image_builder

Length of output: 9157


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- role files ---'
git ls-files | rg '(^|/)(tasks|meta)/|tests|README.md'

printf '%s\n' '--- role task structure ---'
if command -v ast-grep >/dev/null 2>&1; then
  ast-grep outline tasks --lang yaml || true
  ast-grep outline meta/argument_specs.yml --lang yaml || true
fi

printf '%s\n' '--- relevant role logic ---'
rg -n -C 5 'ib_daemon|not_a_valid_daemon|assert_role_vars|argument_specs|include_role' \
  tasks meta tests README.md

Repository: linux-system-roles/image_builder

Length of output: 9272


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

test = Path("tests/tests_invalid_input.yml").read_text()
main = Path("tasks/main.yml").read_text()
args = Path("meta/argument_specs.yml").read_text()
readme = Path("README.md").read_text()

gates = re.findall(r"ansible_version\.full is version\('([^']+)', '>= '\)|ansible_version\.full is version\('([^']+)', '>='\)", test)
print("argument-spec test gates:", re.findall(r"ansible_version\.full is version\('([^']+)', '>='\)", test))
print("README validation statement:", next(
    (line.strip() for line in readme.splitlines() if "meta/argument_specs.yml" in line),
    "<missing>",
))
print("argument-spec declares ib_daemon choices:", bool(
    re.search(r"ib_daemon:.*?choices:", args, re.S)
))
print("role task order:")
for name in ("include_tasks: assert_role_vars.yml", 'service:', 'name: "{{ ib_daemon }}"'):
    print(f"  {name!r}:", main.find(name))
print("invalid daemon is passed to include_role:", "ib_daemon: not_a_valid_daemon" in test)
assert re.findall(r"ansible_version\.full is version\('([^']+)', '>='\)", test) == ["2.10", "2.10"]
assert main.find("include_tasks: assert_role_vars.yml") < main.find('name: "{{ ib_daemon }}"')
PY

Repository: linux-system-roles/image_builder

Length of output: 502


Require ansible-core 2.11 for role argument-spec validation.

Change both version gates in tests/tests_invalid_input.yml from 2.10 to 2.11. Otherwise, the rescue block can treat a later role failure as argument-spec validation. State the ansible-core 2.11 requirement in README.md.

📍 Affects 2 files
  • tests/tests_invalid_input.yml#L7-L10 (this comment)
  • README.md#L15-L15
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/tests_invalid_input.yml` around lines 7 - 10, Update both
ansible_version.full gates in tests/tests_invalid_input.yml to require version
2.11 or newer, preserving the invalid-input validation flow. Document the
ansible-core 2.11 requirement in README.md at the referenced location.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant