I'd also be super interested in some way to do this. To me this is a very
sane use case, and the Ansible appears to allow the use of until: along
with with_items:, but appears to just ignore the until statement. If this
is not supported ideally there would be some sort of syntax issue.
Would the Ansible team be willing to take a pull request to allow until
evaluations in the context of a with_items loop?
For more clarity here is an example play. Lets say we want to send a
update to a single web server out of a set, and you want to stop after the
first successful call. Maybe the calls are not idempotent, maybe you don't
want to add extra load...
here is a test play with until and with_items, and until apparently not
being evaluated.
- hosts: localhost
gather_facts: no
tasks:
- name: test
# action: debug msg="cluster host {{ item }}"
# action: uri timeout=2 url={{ item }}
action: shell curl --max-time 1 {{ item }} >/dev/null
with_items: "{{input_hosts|shuffle}}"
register: put_status
until: put_status.rc == 0
here is the output executing with an input array of URLs, you can see the
first URL works yet it keeps going
ansible-playbook -vv -i ../hosts --sudo test2.yml
--extra-vars='{"input_hosts": ["https://www.google.com",
"https://www.snargoblarg.com"]}'
PLAY [localhost]
**************************************************************
TASK: [test]
******************************************************************
<127.0.0.1> REMOTE_MODULE command curl --max-time 1 https://www.google.com
>/dev/null #USE_SHELL
changed: [127.0.0.1] => (item=https://www.google.com) => {"attempts": 0,
"changed": true, "cmd": "curl --max-time 1 https://www.google.com
>/dev/null", "delta": "0:00:00.555617", "end": "2016-01-04
23:32:04.951993", "item": "https://www.google.com", "rc": 0, "start":
"2016-01-04 23:32:04.396376", "stderr": " % Total % Received % Xferd
Average Speed Time Time Time Current\n
Dload Upload Total Spent Left Speed\n\r 0 0 0 0
0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 18908 0
18908 0 0 35322 0 --:--:-- --:--:-- --:--:-- 36152", "stdout":
"", "warnings": ["Consider using get_url module rather than running curl"]}
<127.0.0.1> REMOTE_MODULE command curl --max-time 1
https://www.snargoblarg.com >/dev/null #USE_SHELL
<127.0.0.1> REMOTE_MODULE command curl --max-time 1
https://www.snargoblarg.com >/dev/null #USE_SHELL
Result from run 1 is: {'cmd': 'curl --max-time 1
https://www.snargoblarg.com >/dev/null', 'end': '2016-01-04
23:32:11.354140', 'stdout': u'', 'changed': True, 'attempts': 1, 'start':
'2016-01-04 23:32:11.188499', 'delta': '0:00:00.165641', 'stderr': ' %
Total % Received % Xferd Average Speed Time Time Time Current\n Dload
Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0curl: (6) Could not resolve host: www.snargoblarg.com', 'rc': 6,
'warnings': ['Consider using get_url module rather than running curl']}
<127.0.0.1> REMOTE_MODULE command curl --max-time 1
https://www.snargoblarg.com >/dev/null #USE_SHELL
Result from run 2 is: {'cmd': 'curl --max-time 1
https://www.snargoblarg.com >/dev/null', 'end': '2016-01-04
23:32:16.868708', 'stdout': u'', 'changed': True, 'attempts': 2, 'start':
'2016-01-04 23:32:16.703207', 'delta': '0:00:00.165501', 'stderr': ' %
Total % Received % Xferd Average Speed Time Time Time Current\n Dload
Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0curl: (6) Could not resolve host: www.snargoblarg.com', 'rc': 6,
'warnings': ['Consider using get_url module rather than running curl']}
<127.0.0.1> REMOTE_MODULE command curl --max-time 1
https://www.snargoblarg.com >/dev/null #USE_SHELL
Result from run 3 is: {'cmd': 'curl --max-time 1
https://www.snargoblarg.com >/dev/null', 'end': '2016-01-04
23:32:22.253845', 'stdout': u'', 'changed': True, 'attempts': 3, 'start':
'2016-01-04 23:32:22.231865', 'delta': '0:00:00.021980', 'stderr': ' %
Total % Received % Xferd Average Speed Time Time Time Current\n Dload
Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0curl: (6) Could not resolve host: www.snargoblarg.com', 'rc': 6,
'warnings': ['Consider using get_url module rather than running curl']}
failed: [127.0.0.1] => (item=https://www.snargoblarg.com) => {"attempts":
3, "changed": true, "cmd": "curl --max-time 1 https://www.snargoblarg.com
>/dev/null", "delta": "0:00:00.021980", "end": "2016-01-04
23:32:22.253845", "failed": true, "item": "https://www.snargoblarg.com",
"rc": 6, "start": "2016-01-04 23:32:22.231865", "warnings": ["Consider
using get_url module rather than running curl"]}
stderr: % Total % Received % Xferd Average Speed Time Time
Time Current
Dload Upload Total Spent Left
Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
0curl: (6) Could not resolve host: www.snargoblarg.com
msg: Task failed as maximum retries was encountered
FATAL: all hosts have already failed -- aborting
On Wednesday, August 5, 2015 at 7:20:55 AM UTC-7, Chuck Carlino wrote:
>
> https://groups.google.com/forum/#!topic/ansible-project/z9iD55-4pPs is a
> similar case.
>
> On Tuesday, August 4, 2015 at 7:59:33 AM UTC-7, Pete Ahearn wrote:
>>
>> Bump. Is there really no way to do this currently?
>>
>> On Friday, May 1, 2015 at 3:02:36 PM UTC-4, Vladislav Rastrusny wrote:
>>>
>>> My use case is the following:
>>>
>>> I have a list of ntpd servers and I want to run ntpdate against the
>>> list. But since one sucessful sync is enough, I would like to break the
>>> cycle after the first successfully executed sync. How would I do that
>>> currently? As I understand do-until loop will not work in this case, right?
>>>
>>>
>>>
>>> четверг, 11 декабря 2014 г., 19:41:11 UTC+3 пользователь Michael DeHaan
>>> написал:
>>>>
>>>> "Anyway... is there a way of breaking out of a loop or would patches
>>>> be accepted to provide such a mechanism?"
>>>>
>>>> Still want to understand your use case before we start talking
>>>> implementation and language changes to find the best way to express the
>>>> construct.
>>>>
>>>> Ultimately Ansible isn't a arbitrary scripting language, and I don't
>>>> want to make it one - but we do want to find the best possible way to
>>>> express what you may want to express.
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Dec 11, 2014 at 11:33 AM, Hugh Saunders <[email protected]>
>>>> wrote:
>>>>
>>>>> On 11 December 2014 at 16:18, Michael DeHaan <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> if you are downloading tars of git repos from GitHub from lots of
>>>>>> production servers, that seems to be a bit of a bad practice to me that
>>>>>> assaults the mirror.
>>>>>>
>>>>>> I would consider setting up a mirror of all that content on one
>>>>>> server initially and then have your individual production nodes download
>>>>>> off that box.
>>>>>>
>>>>>
>>>>> I haven't said that I had multiple servers downloading the same
>>>>> content.
>>>>>
>>>>> Anyway... is there a way of breaking out of a loop or would patches be
>>>>> accepted to provide such a mechanism?
>>>>>
>>>>> --
>>>>> 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/CAAD%2BY3VzJH1cLe6QOBC%3DQ9z_YtZSes15Q0o%2BPj-Zd%2BEKgqKXFA%40mail.gmail.com
>>>>>
>>>>> <https://groups.google.com/d/msgid/ansible-project/CAAD%2BY3VzJH1cLe6QOBC%3DQ9z_YtZSes15Q0o%2BPj-Zd%2BEKgqKXFA%40mail.gmail.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/be89c3f3-108b-40ea-a526-8e5abfc6970a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.