The Parameter Validation Verifier checks that the parameters passed to Ansible modules match expected values. This is crucial for ensuring that modules are not only called the correct number of times but also with the right parameters.
This verifier allows you to validate specific parameter values, ensuring your playbook is passing the correct data to each module.
Configure parameter validation in your scenario YAML under the verify.parameter_validation section:
verify:
parameter_validation:
"module.name":
- param1: "expected value 1"
param2: "expected value 2"
- param1: "different value"
param2: "for second call"- The top-level keys are the fully qualified module names to validate.
- Each module has an array of parameter sets, one for each expected call.
- Each parameter set is an object mapping parameter names to their expected values.
- The order of parameter sets corresponds to the order of module calls.
For each module call, you can specify:
| Parameter | Value |
|---|---|
| Any valid module parameter | The expected value for that parameter |
The verifier:
- Compares each expected parameter set with the corresponding actual module call
- Checks that each parameter has the expected value
- Reports any mismatches in parameter values
- Fails verification if parameters don't match, if a parameter is missing, or if there are fewer actual calls than expected
Parameter validation is ideal for:
- Data Verification: Ensuring correct values are passed to modules
- End-to-End Testing: Validating that computed values flow correctly through the playbook
- Integration Testing: Confirming that modules receive the correct data derived from other module outputs
- Conditional Logic: Verifying that parameters change correctly based on playbook conditions
verify:
parameter_validation:
community.general.mail:
- subject: "Project Notification"
to: "admin@example.com"
body: "Project status notification"verify:
parameter_validation:
my.modules.myservice_create_incident:
- incident_type: "alert"
priority: "high"
description: "Critical system failure"
- incident_type: "request"
priority: "medium"
description: "Feature activation request"You can validate just the important parameters without specifying all of them:
verify:
parameter_validation:
ansible.builtin.template:
- src: "templates/email_template.j2"
# Other parameters are not validatedHere's a complete scenario file using parameter validation:
name: "Project Email Notification Test"
description: "Tests that email notifications have correct parameters"
playbook: "project_ttl_notification.yaml"
# Mock service responses
service_mocks:
my.modules.myservice_login:
success: true
access_token: "mock-token-value"
# Other mocks...
# Verification configuration
verify:
expected_calls:
community.general.mail: 1
parameter_validation:
community.general.mail:
- to: "project-owner@example.com, project-requestor@example.com"
subject: "Project BIQ-123 Expiration Notification"
body_contains: "will be archived in 30 days"For long text fields like email bodies, you can check that they contain certain substrings:
verify:
parameter_validation:
community.general.mail:
- subject_contains: "Expiration"
body_contains: "will be archived in"Note: The _contains suffix is not a built-in feature but a convention that can be implemented in a custom verifier extension.
If the parameter validation expects more calls than actually occurred, the verification will fail with a message indicating that the expected call was missing.
- Validate Important Parameters: Focus on critical parameters rather than validating everything
- Use With Call Count: Combine with module call count verification for complete testing
- Order Matters: Parameter sets are matched to calls in order, so ensure your expectations match the calling sequence
- String Comparison: Parameter values are compared as strings, so formatting matters
- Space Sensitivity: Leading/trailing whitespace is stripped during comparison
If parameter validation fails:
- Check the module call details in the playbook statistics
- Verify that parameter names match exactly, including case
- Look for whitespace or formatting differences in values
- Confirm that the expected calls occur in the order specified