"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. "

Would like to step back to use cases first before we propose it be done
with the "with_<foo>" here, as that's not how that part works.

Curious what kinds of files you are downloading - for instance, package
managers like yum already do this, etc.



On Thu, Dec 11, 2014 at 10:41 AM, Hugh Saunders <[email protected]> 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 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
> <https://groups.google.com/d/msgid/ansible-project/be63ee7b-502b-40a8-a776-cf05d8534c1c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgzi%3DOhWEfGgVQ0pdZcQW8F1nLcTvoHi9H8ATPUO0es01g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to