# uri Module - Wait For Satellite Task to Complete

**URL:** <https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549>\
**Category:** Ansible Project\
**Created:** [June 12, 2019, 4:14pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549 "2019-06-12T16:14:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cade\_Lambert](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cade\_Lambert](https://forum.ansible.com/u/Cade_Lambert)\
**Post date:** [June 12, 2019, 4:14pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/1 "2019-06-12T16:14:25Z")

</div>

I’m writing a playbook to publish new Content View versions and promote the new version to our Lifecycle Environments using the uri module. I’m trying to create a task that will query the task ID until it reports a result of ‘success’. I’ve tried the following:

- name: Get the tasks list from Satellite  
uri:  
url: [https://satelitlite-server/foreman\_tasks/api/tasks](https://satelitlite-server/foreman_tasks/api/tasks)  
method: GET  
body:  
order: ‘id DESC’  
organization\_id: 3  
user: “{{ satellite\_user }}”  
password: “{{ satellite\_pass }}”  
force\_basic\_auth: yes  
validate\_certs: no  
body\_format: json  
register: tasks\_list

- name: Wait for new Content View version to finish publishing

uri:  
url: “[https://satellite-server/foreman\_tasks/api/tasks/](https://satellite-server/foreman_tasks/api/tasks/){{ tasks\_list.json.results[4].id }}”  
method: GET  
status\_code: 200  
validate\_certs: no  
user: “{{ satellite\_user }}”  
password: “{{ satellite\_pass }}”  
force\_basic\_auth: yes  
body\_format: json  
register: task\_result  
until: task\_result.json.results[4].result == ‘success’  
retries: 60  
delay: 20

This gives me an error of:

TASK [Wait for new Content View version to finish publishing] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“msg”: “The conditional check ‘task\_result.json.results[4].result == ‘success’’ failed. The error was: error while evaluating conditional (task\_result.json.results[4].result == ‘success’): ‘dict object’ has no attribute ‘results’”}

I’m guessing I can’t query a variable that’s registered in the same task? Does anyone know an alternative method other than just pausing the playbook for a few minutes to let the publish task finish?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 12, 2019, 4:37pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/2 "2019-06-12T16:37:14Z")

</div>

You can, but the error is telling you that the JSON response, didn’t have a `results` key. You need to account for the fact, that you might not always get the response you expect.

Maybe like:

until: (task\_result.json.results|default([0, 1, 2, 3, dict(result=‘NOT\_SUCCESS’)))[4].result == ‘success’

In any case, your until makes a lot of assumptions about the data you expect to be there, you need to work from the perspective of not having what you expect.

---

<div class="post-metadata">

**Author:** ![Cade\_Lambert](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cade\_Lambert](https://forum.ansible.com/u/Cade_Lambert)\
**Post date:** [June 12, 2019, 5:11pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/3 "2019-06-12T17:11:10Z")

</div>

Can you explain what you’re doing with the until line you posted?

So I know what’s in task\_result.json.results[4].result. Here’s what I get if I debug as my next task:

- debug:  
var: tasks\_list.json.results[4].result

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“tasks\_list.json.results[4].result”: “success”  
}

That’s why I’m confused, because according to that debug, the until line should work.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 12, 2019, 5:20pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/4 "2019-06-12T17:20:29Z")

</div>

The idea, is that if `results` isn’t defined, to provide a default for the until logic to complete.

You are using `results[4]`, which means it’s the 5th element (now I want to go watch a movie).

Then in the 5th element of results, you are inspecting the `result` key, for a value of `success`.

This just says when `results` is not defined, use the default of [0,1,2,3, dict(result=‘NOT\_SUCCESS’)]

the 0-3 elements, are useless, and don’t matter, it’s just there to make sure that the 5th element ([4]) is a dict/hash that matches your expectations.

---

<div class="post-metadata">

**Author:** ![Cade\_Lambert](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cade\_Lambert](https://forum.ansible.com/u/Cade_Lambert)\
**Post date:** [June 12, 2019, 5:26pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/5 "2019-06-12T17:26:26Z")

</div>

Got it, thanks for the explanation. I’ll try that and see where it gets me.

---

<div class="post-metadata">

**Author:** ![Cade\_Lambert](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cade\_Lambert](https://forum.ansible.com/u/Cade_Lambert)\
**Post date:** [June 12, 2019, 6:53pm UTC](https://forum.ansible.com/t/uri-module-wait-for-satellite-task-to-complete/30549/6 "2019-06-12T18:53:03Z")

</div>

I guess I was staring at this too long and was referencing the wrong variable, or I got lost in the JSON output of the results, but the answer ended up being task\_result.json.result == ‘success’, which makes perfect sense.

Now I just need to figure out how to do this, in a loop, for each lifecycle environment promotion.
