Search code examples
ansiblemolecule

Is negative testing of Ansible roles possible with Molecule?


I would like to perform negative testing of an Ansible role, that is testing whether the role handles errors in an expected fashion. To do this I invoke the role in a Molecule scenario with a parameter that will result in an error being raised using ansible.builtin.fail. In the Molecule scenario I also have a verify.yml file in which verify that the role has not produced result it would if there hadn't been an error. From what I can tell the Molecule scenario in question fails and the verification is never performed.
My question is thus: Is it possible to have this kind of negative tests of Ansible scenarios using Molecule other than using a block-rescue around the invocation of the role in the Molecule converge.yml file?

If so, how?


Solution

  • Having found no other method, I ended up using block-rescue in the converge.yml file of my Molecule test.