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.
Summary
mock_ansible_adapter.pydeletes thesuccesskey from the mock response before passing it toexit_json/fail_json. Any playbook task that branches onresult.successwill 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.pyReproducer
Scenario YAML:
Playbook task:
The
when:condition silently evaluates to falsy on every run regardless of thesuccessvalue in the mock.Expected behaviour
success(or any user-defined field) present in the mock response should be forwarded to the playbook viaexit_jsonso thatresult.successis available to subsequent tasks.Suggested fix
Use a dedicated internal key (e.g.
_mock_should_fail) for flow control instead of reusingsuccess, 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 onresult.successin the playbook under test.