Answers: <p>Changing <code>list([])</code> to <code>list</code> resolves that specific error.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-10-01T10:33:07.700Z
Answers: 2022-10-01T10:33:07.700Z
Answers: Cyber Axe
Body: <p>I am trying to take a dictionary from one or more async tasks &quot;register: task_variable&quot; 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</p>
  <p>But i am getting an &quot;Unexpected templating type error&quot; with the Jinja &quot;sync_do_list() takes 1 positional argument but 2 were given&quot;</p>
  <p>I've been trying various things for hours too many to remember and i just cant get past this</p>
  <p>Here is the code in it's current form:</p>
  <pre><code>loop: &quot;{{ (task_variable.results|default({}, true)) | selectattr('ansible_job_id') | map(attribute='ansible_job_id') | list([]) }}&quot;
  </code></pre>
  <p>Some of the wait tasks add together multiple test_variables if multiple asyncs need to complete to proceed</p>
  <p>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</p>
  <p>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.</p>
  <p>Edit:</p>
  <p>So to fix that error I had to change list([]) to list</p>
  <p>The end result however is has been changed to</p>
  <pre><code>loop: &quot;{{ [task1, task2, task3, task4] | selectattr('results', 'defined') | map(attribute='results') | selectattr('ansible_job_id', 'defined') | map(attribute='ansible_job_id') | list }}&quot;
  </code></pre>
  <p>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</p>
  <p>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.</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-09-30T23:02:59.127Z
Comments: `task_variable.result` vs. `task_variable.results`. Follow the last [example](https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html#run-tasks-concurrently-poll-0).
Comments: Vladimir Botka
Comments: CC BY-SA 4.0
Comments: 2022-09-30T23:54:02.857Z
Comments: 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.
Comments: Cyber Axe
Tags: <ansible><yaml><jinja>
Title: Ansible / Jinja2 Unexpected templating type error
UserDisplayName: Cyber Axe
ThreadText: # Ansible / Jinja2 Unexpected templating type error
  
  (Asked by: username_0 on 2022-09-30)
  
  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.
  
  **Tags:** ansible, yaml, jinja
  
  > **Comments:**
  > **username_1**: `task_variable.result` vs. `task_variable.results`. Follow the last [example](https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html#run-tasks-concurrently-poll-0).  
  > **username_0**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-10-01. Score: 0
  
  Changing `list([])` to `list` resolves that specific error.
  
  
  ---
  
  