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.

On Wed, Jun 12, 2019 at 12:11 PM Cade Lambert <[email protected]> wrote:

> 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.
>
> On Wednesday, June 12, 2019 at 12:38:06 PM UTC-4, Matt Martz wrote:
>>
>> 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.
>>
>> On Wed, Jun 12, 2019 at 11:14 AM Cade Lambert <[email protected]> wrote:
>>
>>> 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
>>>       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/{{
>>> 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?
>>>
>>> --
>>> 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 post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/6f35ca5c-1c4c-439c-bf05-42a5ad6fe478%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/6f35ca5c-1c4c-439c-bf05-42a5ad6fe478%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> Matt Martz
>> @sivel
>> sivel.net
>>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7c683512-75d6-4707-9689-d76f522adc6a%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7c683512-75d6-4707-9689-d76f522adc6a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9zHL%3DZmXqPNmVUtWfdJHi5cv5GmEnPOPuZ2i9cit%2BNsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to