# Proposal: allow infinite recursion in until: loops

**URL:** <https://forum.ansible.com/t/proposal-allow-infinite-recursion-in-until-loops/19638>\
**Category:** Ansible Developer\
**Created:** [October 28, 2015, 2:53pm UTC](https://forum.ansible.com/t/proposal-allow-infinite-recursion-in-until-loops/19638 "2015-10-28T14:53:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Kellogg-Stedma1](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@Lars\_Kellogg-Stedma1](https://forum.ansible.com/u/Lars_Kellogg-Stedma1)\
**Post date:** [October 28, 2015, 2:53pm UTC](https://forum.ansible.com/t/proposal-allow-infinite-recursion-in-until-loops/19638/1 "2015-10-28T14:53:45Z")

</div>

I submitted this PR yesterday:

&nbsp;&nbsp;[https://github.com/ansible/ansible/pull/12932](https://github.com/ansible/ansible/pull/12932)

It seems like a no-brainer to me, but opinions differ and jimi-c  
suggested I bring it to the list for discussion. First, let me  
describe my motivation for this change:

I am using ansible to (a) start servers in OpenStack and then (b)  
configure those servers. In order for (b) to happen, I need to wait  
for cloud-init on the servers to complete the initial system  
provisioning process, which depending on the environment may happen in  
seconds or may take several minutes.

In this situation, the `wait_for` module simply isn't appropriate: ssh  
will be available before cloud-init has configured the necessary ssh  
keys.

I can of course simply set "retries" to "a very large number":

&nbsp;&nbsp;&nbsp;&nbsp;- command: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssh -o BatchMode=yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;centos@{{myserver.server.public\_v4}} true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;until: result|success  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retries: 300

But I really hate arbitrary constants. I'd much rather be able to do  
something like:

&nbsp;&nbsp;&nbsp;&nbsp;- command: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssh -o BatchMode=yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;centos@{{myserver.server.public\_v4}} true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;until: result|success  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retries: -1

...and have ansible loop indefinitely until the task completes.  
jimi-c suggests that:

> I believe this would be confusing and potentially bad for users as they  
> could have a play run indefinitely.

...but I'm writing these playbooks for myself (which I imagine is true  
for many people), and in general I'm in favor not introducing  
artificial restrictions on the way in which a utility operates  
(because someone else may want to use the tool in a way that I hadn't  
even imagined).

Anyway, that's my spiel. Let me know if you think I'm a crazy person.

PS:

What I \*really\* wanted to do in this case was:

&nbsp;&nbsp;&nbsp;&nbsp;- ping:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;until: result|success

Because the question I am trying to answer is effectively, "is the  
remote host configured such that ansible will run successfully", and  
a successful result from the above play would authoritatively answer  
that question. Unfortunately, the above will result in connection  
errors before the remote ssh is configured appropriately, and  
connection errors will always trigger a task failure regardless of  
until: or ignore\_errors:.

---

<div class="post-metadata">

**Author:** ![Dan\_Rue](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@Dan\_Rue](https://forum.ansible.com/u/Dan_Rue)\
**Post date:** [October 28, 2015, 3:24pm UTC](https://forum.ansible.com/t/proposal-allow-infinite-recursion-in-until-loops/19638/2 "2015-10-28T15:24:36Z")

</div>

I can’t think of a situation where you’d ever want ansible to actually run forever, so I would oppose this proposal.

I noticed you’re not specifying a delay in your loop. Consider this:

- command: \>  
ssh -o BatchMode=yes  
centos@{{myserver.server.public\_v4}} true  
register: result  
until: result|success  
retries: 300

delay: 300

With a 5 minute delay between retries, your loop will terminate after ~25 hours. This gives you a reasonable upper bound, without risking an actual infinite loop.

Dan

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [October 28, 2015, 3:28pm UTC](https://forum.ansible.com/t/proposal-allow-infinite-recursion-in-until-loops/19638/3 "2015-10-28T15:28:25Z")

</div>

> I can't think of a situation where you'd ever want ansible to actually  
> run forever, so I would oppose this proposal.

I think the use case is less like "I want this to run forever", and more  
like "I want this to run until I manually stop it -- I never want it to  
decide on its own to exit unless it succeeds".

> I believe this would be confusing and potentially bad for users as  
> they could have a play run indefinitely.

I think "-1" is a reasonable way to represent that; it seems to me very  
unlikely that any user would accidentally put that in there without  
knowing what it meant.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
