Summary
When a loop:-ed task fails, Ansible wraps all per-item failures into a single task-level error with the fixed message "One or more items failed". The error_message defined in the mock is shown in verbose output but is not what the framework's error verifier matches against. Tests that assert a custom expected_errors.message on a looped failure will always fail.
Affected area
Interaction between Ansible's loop error aggregation and ansible_playtest/verifiers/error.py.
Reproducer
Scenario YAML:
service_mocks:
my_namespace.my_collection.my_module:
success: false
error_message: "Project already exists"
expected_errors:
- task: "Create project"
message: "Project already exists" # ← never matches; actual is "One or more items failed"
Playbook task:
- name: Create project
my_namespace.my_collection.my_module:
name: "{{ item }}"
loop: "{{ projects }}"
Expected behaviour
Option A: The error verifier should inspect per-item failure messages in addition to the task-level wrapper message.
Option B: Document clearly that expected_errors.message for looped tasks must be "One or more items failed", and provide a separate field (e.g. item_message) to assert per-item error content.
Workaround
Set expected_errors.message: "One or more items failed" for any looped failure scenario.
Summary
When a
loop:-ed task fails, Ansible wraps all per-item failures into a single task-level error with the fixed message"One or more items failed". Theerror_messagedefined in the mock is shown in verbose output but is not what the framework's error verifier matches against. Tests that assert a customexpected_errors.messageon a looped failure will always fail.Affected area
Interaction between Ansible's loop error aggregation and
ansible_playtest/verifiers/error.py.Reproducer
Scenario YAML:
Playbook task:
Expected behaviour
Option A: The error verifier should inspect per-item failure messages in addition to the task-level wrapper message.
Option B: Document clearly that
expected_errors.messagefor looped tasks must be"One or more items failed", and provide a separate field (e.g.item_message) to assert per-item error content.Workaround
Set
expected_errors.message: "One or more items failed"for any looped failure scenario.