0

I am trying to take a dictionary from one or more async tasks "register: task_variable" then collecting it as a list based on its id's and running a wait task using async_status on the resulting list generated from the id's

But i am getting an "Unexpected templating type error" with the Jinja "sync_do_list() takes 1 positional argument but 2 were given"

I've been trying various things for hours too many to remember and i just cant get past this

Here is the code in it's current form:

loop: "{{ (task_variable.results|default({}, true)) | selectattr('ansible_job_id') | map(attribute='ansible_job_id') | list([]) }}"

Some of the wait tasks add together multiple test_variables if multiple asyncs need to complete to proceed

Some of the tasks that generate the task_variables are wrapped in whens so may never generate a variable hence why i am doing a loop like that to be able to handle them all as appropriate

The code is on my work laptop so hard to get it over without manually typing it, but this is the only piece that really matters, any help would be appreciated. thanks.

Edit:

So to fix that error I had to change list([]) to list

The end result however is has been changed to

loop: "{{ [task1, task2, task3, task4] | selectattr('results', 'defined') | map(attribute='results') | selectattr('ansible_job_id', 'defined') | map(attribute='ansible_job_id') | list }}"

Where any of the tasks can be empty or undefined and they will get filtered out correctly but must remain as a list even if only checking one task

The resulting {{ item }} can be passed into an async_status and avoids having to check what is defined and what isn't via when statements and such.

2
  • task_variable.result vs. task_variable.results. Follow the last example. Commented Sep 30, 2022 at 23:02
  • Ah, i typoed that when i copied it to my pc to write this question, the actual code does have an s in it that produces that errror, i've edited it to reflect that. that example looks mostly like what i need but won't it still fail if the variable is undefined? I'll give it a try, thanks.
    – Cyber Axe
    Commented Sep 30, 2022 at 23:54

1 Answer 1

0

Changing list([]) to list resolves that specific error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.