conditional for Ansible to exit success (sys.exit(0))

I have a condition under which I need Ansible to exit without an error (i.e. sys.exit(0)). Is there a means by which to do this? I.e. the complement to the fail module.

Thanks!
Robb

That's curious situation. Perhaps you can call ansible this way so the
result of the subshell is always success?

$(ansible-playbook play.yml; exit 0); echo $?
0

After a quick look in the plugins code I don't see a way to hook into
Ansible and change the exit code. If you want to mess with the code
directly, edit ansible-playbook and change the return code in case of
errors. However, it's a non-standard change you'll have to keep track of
between updates.

Giovanni

I have a condition under which I need Ansible to exit without an error
(i.e. sys.exit(0)). Is there a means by which to do this? I.e. the
complement to the fail module.

That’s curious situation. Perhaps you can call ansible this way so the
result of the subshell is always success?

$(ansible-playbook play.yml; exit 0); echo $?
0

Thanks for the input Giovanni. A sub-shell approach is interesting - I’ll experiment with trap inheritance settings. I need to exit success because I have Bash trap $mutex_remove_cmd ERR, on actual error conditions which removes a target environment’s mutex. In my situation, if the mutex exists, then I want Ansible to stop and provide a polite message that the target environment is being updated by Ansible elsewhere, without removing the mutex. If there is an actual error/failure, the mutex should be removed, and the state of the environment restored. The typical use-case is a shared testing environment, where CI/CD could be doing a deployment/update or an engineer could be testing their own updates. Only one gets access to the testing environment at any one time.

After a quick look in the plugins code I don’t see a way to hook into
Ansible and change the exit code. If you want to mess with the code
directly, edit ansible-playbook and change the return code in case of
errors. However, it’s a non-standard change you’ll have to keep track of
between updates.

Giovanni

I’ve done something similar with several of the ec2_ core modules due to the pace of PR acceptance in the ansible-modules-core project. But that is a bit easier to managed/track upstream, via site-local library/ pathing, IMO, than doing the same to Ansible itself.

Regards,
Robb