Skip to content

success key is silently stripped from mock response — playbook can never read it #2

Description

@jorge-romero

Summary

mock_ansible_adapter.py deletes the success key from the mock response before passing it to exit_json / fail_json. Any playbook task that branches on result.success will always see the key as undefined, silently taking the wrong conditional branch with no error or warning.

Affected file

ansible_playtest/ansible_mocker/mock_ansible_adapter.py

if "success" in response_data:
    is_failure = not response_data["success"]
    del response_data["success"]   # ← stripped here, never reaches playbook

Reproducer

Scenario YAML:

service_mocks:
  my_module:
    success: true
    token: "abc123"

Playbook task:

- name: Check result
  ansible.builtin.debug:
    msg: "ok"
  when: result.success   # ← always undefined → task always skipped

The when: condition silently evaluates to falsy on every run regardless of the success value in the mock.

Expected behaviour

success (or any user-defined field) present in the mock response should be forwarded to the playbook via exit_json so that result.success is available to subsequent tasks.

Suggested fix

Use a dedicated internal key (e.g. _mock_should_fail) for flow control instead of reusing success, so any other key the user puts in the response dict is passed through unchanged.

Workaround

Use a different response key (e.g. failed, status, or a domain-specific field) to signal failure state. Never rely on result.success in the playbook under test.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions