Skip to content

Looped failure tasks produce wrapper error message "One or more items failed" — per-item error_message is not matchable #6

@jorge-romero

Description

@jorge-romero

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions