I messed around with this a little bit. It gets a little complicated to
parse the next available hostname from the output but I did get it to
work.
- set_fact:
first: "{{ result.results|
selectattr('rc', 'equalto', 1)|
map(attribute='item')|
first }}"
- debug:
msg: "{{ result.results[first|int-1].cmd | regex_search('(?<=\\s).*')
}}"
This will give me:
ok: [localhost] => {
"msg": "hostname04"
}
So yes, this is another way I could achieve finding the next available
hostname.
On Thursday, June 25, 2020 at 11:56:48 AM UTC-4, Vladimir Botka wrote:
>
> > > > On Thu, 25 Jun 2020 06:51:12 -0700 (PDT)
> > > > Cade Lambert <[email protected] <javascript:>> wrote:
> > > > I'd like it to stop processing the loop at item=4, since that's the
>
> > > > first success.
>
> > > This is not possible atm. All items in the loop will be processed. The
> > > details have already been discussed here
> > > https://groups.google.com/forum/#!topic/ansible-project/uJqSmkKTpZc
>
> > Ok, I tried the 'hack' ... Ugly but it works.
>
> There is no hack available to break a loop. All items of a loop will be
> processed atm. Wouldn't be better to test the registered results? For
> example
>
> - command: '[ "{{ item }}" -gt "3" ]'
> loop: "{{ range(1, 5 + 1)|list }}"
> register: result
> ignore_errors: true
> - set_fact:
> first: "{{ result.results|
> selectattr('rc', '==', 0)|
> map(attribute='item')|
> first }}"
> - debug:
> var: first
>
> gives
>
> first: '4'
>
> --
> Vladimir Botka
>
--
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/3badff86-41c0-4ea3-99f7-a83740a9539co%40googlegroups.com.