Hello,
Molecule is perfect to test that play is correctly executed (different inputs, ...), but is there a way to test that some executions are correctly failing ?
e.g: don't stop when converge is failed to execute at minimum verify phase, and perhaps check which task or message error content in verify phase ?
It could be very valuable to test when ansible role checks some prerequisites (like tools installation, ...).
Sample:
Consider this very valuable role with a "tasks/main.yml" :
- name: Verify prerequisites
stat:
path: /tmp/prerequisites.file
register: prerequisites_file
failed_when: not prerequisites_file.stat.exists
- name: Do job
copy:
content: Job done!
dest: /tmp/job.file
The correct behavior can be mocked with a "molecule/default/prepare.yml" like :
---
- name: Prepare
hosts: all
tasks:
- name: Create prerequisites
copy:
content: prerequisites
dest: /tmp/prerequisites.file
And tested with a "molecule/default/tests/test_default.py" containing:
def test_job(host):
f = host.file('/tmp/job.file')
assert f.exists
assert f.content_string == "Job done!"
Now, if I want test that my role fails correctly when prerequisites are not set/exist/... I can have a test scenario (named test-prerequisites) without any "prepare.yml" and with a "molecule/test-prerequisites/tests/test_default.py" file containing:
def test_prerequisites(host):
f = host.file('/tmp/job.file')
assert not f.exists
But when the converge phase of the scenario "test-prerequisites" is executed, the process is (logically) stopped because my play is failed, so verify phase is not executed (only the destroy phase for cleanup).
The
ignore_errors is not a solution because in this case the "prerequisite check task" doesn't fail and next tasks are executed.
If anybody has achieve this use case, or have some documentation links about this kind of strategy, it will be really appreciable.
Many thanks.
Best regards