I've got a GitLab pipeline that runs some Ansible playbooks in a container. At the end, I want to run some tests to ensure that everything is properly configured, e.g.
- name: Get the Frobzy value
raw: "frobzy -x foobar"
register: frobzy_val
changed_when: false
- name: Check that Frobzy is valid
assert:
that:
- frobzy_val.stdout is match "oogah"
fail_msg: "bad frobzy"
ignore_errors: true # see comments
- name: Get the Blobzy value
raw: "blobzy -y barfoo"
register: blobzy_val
changed_when: false
- name: Check that Blobzy is valid
assert:
that:
- blobzy_val.stdout is match "warra"
fail_msg: "bad blobzy"
ignore_errors: true # see comments
This is all nicely configured so that I get a JUnit report that gets displayed on my GitLab pipeline results.
The problem is, let's say both of these tests fail. If I look at the test results from my pipeline, it correctly displays that the tests failed. Yet the pipeline itself is marked as having passed! If I hadn't taken a detailed look at the test results, I would have assumed that everything is tickety-boo, and merged some potentially broken code.
The reason why the pipeline is marked as successful is because of those ignore_errors: true
settings. It registers an error, but follows the directive that this should not fail the pipeline. But if I set ignore_errors: false
(which is the default behavior), then as soon as the Frobzy test fails, the pipeline will abort and show a failure on the Frobzy test, but since it never ran the Blobzy test, I don't know that Blobzy would have failed, too.
Basically, I want a way to run all my Ansible assertions, even if some of them fail; I want to see all the test results in my pipeline, and I want the pipeline to fail if any tests failed.
How can I do this?