Here you go... https://www.reddit.com/r/ansible/comments/di4o6h/how_to_break_the_loop/
On Thursday, December 11, 2014 at 10:41:55 AM UTC-5, Hugh Saunders wrote: > > Hi All, > I've been asking on IRC, twitter > <https://twitter.com/wherenow_hugh/status/543048678588829696>, and github > <https://github.com/ansible/ansible/issues/9782> about this and was asked > to post to the ML as well so here goes :) > > I would like to be able to exit a with_items loop based on the result of > the previous iteration. Think of it as a generalisation of > with_first_found. > > Two use cases: > > 1. I have a list of mirrors known to host file, I want to iterate over > that list until I successfully retrieve the file, then stop iterating. No > point in downloading the file multiple times. > 2. I have a git ref (branch/tag) and a list of mirrors of that repo ( > git.openstack.org, github.com), I want to resolve that ref to a SHA > without cloning the repo. Run git ls-remote via shell passing in each > remote url in turn until the ref is successfully resolved. No point in > resolving it twice. Note that for this use case I do not want to clone the > repo. > > I'm sure there are other situations where it would be useful to break out > of a loop. > > As explained in the issue, I can think of two ways of doing this, both > would require modifications to ansible: > > 1. Add previous_iteration variable for use in when clause, eg when: > previous_iteration | failed > 2. Allow registered variable to be used within a loop, eg when: > shell_result['results'][-1].rc != 0 > > > Thanks for any insight. > > -- > Hugh Saunders > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a15f0310-08e0-4805-a593-b90115b67a4b%40googlegroups.com.
