My use case is that I’m trying to run integration tests on playbooks - that is, test the playbooks under various scenarios. For each test, I want to spin up a docker container (or several) and use them as the inventory for the playbook being tested by including the playbook. Then I’d like to delete the docker containers.
I’m wondering how to delete the containers when the playbook under test fails (be that expected or not). There doesn’t seem to be any way to recover from a playbook include that fails. It has to be a playbook include because it’s a playbook being tested, and I’d like to pass it the inventory generated in the previous play. But then there’s no way on a playbook include to add handlers or block exception handling or any of the other goodies that are available for tasks. The only thing I could think of is to have something write out the inventory (how?) and feed it to a command task that runs the target playbook, so that the task can be recovered from.
Or is this just a fundamental mismatch with the Ansible Way and I should be considering some other approach entirely?