# Loop until k8s (lookup/query) module returns a valid value

**URL:** <https://forum.ansible.com/t/loop-until-k8s-lookup-query-module-returns-a-valid-value/31050>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [August 15, 2019, 3:21pm UTC](https://forum.ansible.com/t/loop-until-k8s-lookup-query-module-returns-a-valid-value/31050 "2019-08-15T15:21:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thms\_Hmm](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Thms\_Hmm](https://forum.ansible.com/u/Thms_Hmm)\
**Post date:** [August 15, 2019, 3:21pm UTC](https://forum.ansible.com/t/loop-until-k8s-lookup-query-module-returns-a-valid-value/31050/1 "2019-08-15T15:21:27Z")

</div>

Ansible Version: 2.8.1

Hi,

I’m trying to get the status of a Kubernetes StatefulSet and wait till it has a specific value.

The task looks like this:

`

- set\_fact:  
myVar: “{{ query(‘k8s’, host=‘myhost.local’, … kind=‘StatefulSet’, label\_selector=‘app=test’) }}”  
retries: 5  
delay: 30  
until: “myVar[0][‘status’][‘readyReplicas’]|int == 3”

`

The problem I have is, the loop is executed but the “myVar” variable is never updated and has it’s initial value.

Has anyone seen or tried this? Is there an alternative?

Thomas
