Ansible / Jinja2 Unexpected templating type error
-
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.
-
Changing
list([])
tolist
resolves that specific error.