# nested loop

**URL:** <https://forum.ansible.com/t/nested-loop/29759>\
**Category:** Ansible Project\
**Created:** [February 24, 2019, 6:49pm UTC](https://forum.ansible.com/t/nested-loop/29759 "2019-02-24T18:49:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luca\_Cazzaniga](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@Luca\_Cazzaniga](https://forum.ansible.com/u/Luca_Cazzaniga)\
**Post date:** [February 24, 2019, 6:49pm UTC](https://forum.ansible.com/t/nested-loop/29759/1 "2019-02-24T18:49:35Z")

</div>

```auto
hi all, is there a way to make nested loop without using include_tasks
I know it's possible to use with_nested, but how convert this manual example to use only one file? 

#####################
# main.yml
#####################
- name: Run items asynchronously in batch of two items
  vars:
    sleep_durations:
      - 1
      - 2
      - 3
      - 4
      - 5
    durations: "{{ item }}"
  include_tasks: execute_batch.yml
  loop:
    - "{{ sleep_durations | batch(2) | list }}"

#####################
# execute_batch.yml
#####################
- name: Async sleeping for batched_items
  command: sleep {{ async_item }}
  async: 45
  poll: 0
  loop: "{{ durations }}"
  loop_control:
    loop_var: "async_item"
  register: async_results

- name: Check sync status
  async_status:
    jid: "{{ async_result_item.ansible_job_id }}"
  loop: "{{ async_results.results }}"
  loop_control:
    loop_var: "async_result_item"
  register: async_poll_results
  until: async_poll_results.finished
  retries: 30

```
