# Ansible and Satellite 6.4 - Waiting for Promote To Finish

**URL:** <https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079>\
**Category:** Ansible Project\
**Created:** [August 20, 2019, 5:29pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079 "2019-08-20T17:29:26Z")\
**Posts on this page:** 9\
**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:** [August 20, 2019, 5:29pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/1 "2019-08-20T17:29:26Z")

</div>

I created a playbook to connect to Satellite via API, publish new content views, and promote the various lifecycle environments to these new Content View versions, looping through a list of Lifecycle Environments. The issue I’m having is I can’t figure out a way for my task to wait until the promotion of one Lifecycle Environment is completed before attempting to promote the next. If it tries to promote while a promotion is already in progress, the task fails. I’ve added a delay to the task to try to wait it out but that doesn’t always work and was hoping for a more clever solution. Here’s my task:

- name: Promote new RHEL7 version to Lifecycle Environments  
uri:  
url: “[https://satelliteserver/katello/api/v2/content\_view\_versions/](https://satelliteserver/katello/api/v2/content_view_versions/){{ (content\_views7.json.results[0].id | int) }}/promote”  
method: POST  
body:  
description: “Promoted by Tower”  
environment\_id: “{{ item }}”  
organization\_id: 3  
force: true  
user: “{{ satellite\_user }}”  
password: “{{ satellite\_pass }}”  
force\_basic\_auth: yes  
validate\_certs: no  
body\_format: json  
status\_code: 202  
loop:
- 3
- 4
- 5
- 6
- 7
- 8  
loop\_control:  
pause: 180

Any input on a way to wait for the promotion to finish, or a cleaner way of doing the same thing?

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [August 20, 2019, 5:54pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/2 "2019-08-20T17:54:22Z")

</div>

Cade,

Check out [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_loops.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html) There’s delays, retries etc. You can use any of this to accomplish what you want.

---

<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:** [September 5, 2019, 2:16pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/3 "2019-09-05T14:16:26Z")

</div>

So I’m still having trouble with this. Here’s my task:

`

- name: Promote new RHEL7 version to Lifecycle Environments  
uri:  
url: “[https://satellite/katello/api/v2/content\_view\_versions/](https://satellite/katello/api/v2/content_view_versions/){{ (content\_views7.json.results[0].id | int) }}/promote”  
method: POST  
body:  
description: “Promoted by Tower”  
environment\_id: “{{ item }}”  
organization\_id: 3  
force: true  
user: “{{ satellite\_user }}”  
password: “{{ satellite\_pass }}”  
force\_basic\_auth: yes  
validate\_certs: no  
body\_format: json  
status\_code: 202  
register: promote\_rhel7  
loop:
- 3
- 4
- 5
- 6
- 7
- 8  
until: promote\_rhel7.json.result == ‘success’  
retries: 10  
delay: 20

`

I tried this but it error’d out with:

`  
fatal: [localhost]: FAILED! =\> {“msg”: “The conditional check ‘promote\_rhel7.json.result == ‘success’’ failed. The error was: error while evaluating conditional (promote\_rhel7.json.result == ‘success’): ‘dict object’ has no attribute ‘result’”}

`

Which I kind of expected because it doesn’t seem like it’s returning anything. I’m trying to loop through all the lifecycle environments in one task, but I also need to check the tasks from satellite to ensure the promotion is done before it attempts to promote to the next lifecycle environment, or it’ll throw a lock error. I know I could ditch the loop and create a task for each lifecycle environment, and check satellite tasks prior to each promotion, but I was hoping there was a sleeker way to do it.

I’ve used loop\_control and pause previously, but I’d like to know for certain a promote is complete before attempting the next one.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 6, 2019, 6:27am UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/4 "2019-09-06T06:27:14Z")

</div>

I don't know anything about the api you are using so I can't comment on that, but this type of error can be solved by checking if the variable is defined first.

&nbsp;&nbsp;&nbsp;until: promote\_rhel7.json.result is defined and promote\_rhel7.json.result == 'success'

---

<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:** [September 6, 2019, 2:52pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/5 "2019-09-06T14:52:18Z")

</div>

Yeah, it’s not defined because it’s not a value that’s returned when the API call is sent. I’m not sure there’s a way to do what I’m trying to do with a loop.

---

<div class="post-metadata">

**Author:** ![Zolvaring](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@Zolvaring](https://forum.ansible.com/u/Zolvaring)\
**Post date:** [September 6, 2019, 3:28pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/6 "2019-09-06T15:28:18Z")

</div>

I think Kai’s suggestion is correct, don’t know much about your specific use case, but I’ve had similar issues looping with return values. The reason is on there first check the call hasn’t been made yet and “results” won’t exist you’re right, but on subsequent calls within that loop it will, so that extra clause should fix that error.

---

<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:** [September 6, 2019, 5:14pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/7 "2019-09-06T17:14:32Z")

</div>

I tested that just now. It doesn’t work. The API doesn’t send a response about the status of the promote task. When I make the call to promote, it immediately responds with info that it started, and that’s all. So the solution Kai provided really just keeps sending the same API request using the same loop item, because it never gets a response back from the API about result.

root@tower /etc/ansible/playbooks $ ansible-playbook test.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [Promote new RHEL7 version to Lifecycle Environments] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (10 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (9 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (8 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (7 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (6 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (5 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (4 retries left).  
FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (3 retries left).

---

<div class="post-metadata">

**Author:** ![Zolvaring](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@Zolvaring](https://forum.ansible.com/u/Zolvaring)\
**Post date:** [September 7, 2019, 6:55am UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/8 "2019-09-07T06:55:37Z")

</div>

Okay, looking more closely I think I see. I don’t believe “results” becomes populated in a loop object until the end of the first iteration and with a retry technically you have never ended that first iteration. What I would do then is this:

include\_tasks: register\_environment  
loop:

- 3
- 4  
etc

---

<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:** [September 9, 2019, 1:10pm UTC](https://forum.ansible.com/t/ansible-and-satellite-6-4-waiting-for-promote-to-finish/31079/9 "2019-09-09T13:10:39Z")

</div>

Interesting, I’ll try that later. For now, I just went ahead and created the role with each lifecycle environment having it’s own register task and then importing a separate task file that contains the tasks to query the task queue in satellite and wait until the task is finished… I think if I combined that with your idea, it’d probably work and have less code.
