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 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/be63ee7b-502b-40a8-a776-cf05d8534c1c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
