# How to break "until" loop when some conditions meet?

**URL:** <https://forum.ansible.com/t/how-to-break-until-loop-when-some-conditions-meet/33284>\
**Category:** Ansible Project\
**Created:** [June 30, 2020, 11:19am UTC](https://forum.ansible.com/t/how-to-break-until-loop-when-some-conditions-meet/33284 "2020-06-30T11:19:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiang\_chen](https://avatars.discourse-cdn.com/v4/letter/x/ee7513/32.png) [@xiang\_chen](https://forum.ansible.com/u/xiang_chen)\
**Post date:** [June 30, 2020, 11:19am UTC](https://forum.ansible.com/t/how-to-break-until-loop-when-some-conditions-meet/33284/1 "2020-06-30T11:19:09Z")

</div>

### SUMMARY

I need to call one api to get async result, the api result is like

`{ "resultCode": 0, "resultInfo": "cutover is running", "taskStatus": "21" }`

when taskStatus is 21 means the tasks is running, I should wait and contnue to get the result until the taskStatus becomes 20 that means success, but when the taskStatus is 22 means the api fails, and I should break the loop call. But I found that I cann’t use fail\_when with uri module at the same time. So how can I do to continue checking the result for 30min when the result is running and quit when the result is fail?

Here is my task:

> ```auto
> - uri:
> url: "http://10.xx.xx.xx/api/task/verify/"
> follow_redirects: all
> method: GET
> return_content: yes
> status_code: 200
> timeout: 300
> body: '{"hostname": "{{check_box.hostname}}"}' #my variable , but doesn't matter
> body_format: json
> headers:
> Content-Type: "application/json"
> register: current_status
> until:
> - current_status.json.taskStatus == 20
> retries: 180 # try 30 min
> delay: 10
> 
> ```

##### ISSUE TYPE- Documentation Report

##### COMPONENT NAME##### ANSIBLE VERSION

```auto
ansible 2.9.10

```

##### CONFIGURATION

```auto

```

##### OS / ENVIRONMENT

CentOS Linux release 7.6.1810 (Core)
