On Tuesday, February 3, 2015 at 3:39:54 AM UTC-7, Giovanni Tirloni wrote: > On Mon, 02 Feb 2015 16:15 -0800, Robb Wagoner <[email protected] > <javascript:>> > wrote: > > 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 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6cdd7453-60ed-472b-b774-22c2200b35db%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
