# Job slicing & extra vars (AWX)

**URL:** <https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [December 17, 2024, 4:50pm UTC](https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213 "2024-12-17T16:50:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirsikes777](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sirsikes777](https://forum.ansible.com/u/sirsikes777)\
**Post date:** [December 17, 2024, 4:50pm UTC](https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213/1 "2024-12-17T16:50:19Z")

</div>

Greetings all!

I want to rack some of your brains and find out if my goal is possible.

I have a playbook for cloning VM’s with the proxmox\_kvm community module, currently I loop through an extra var “{{ vm\_name }}” that is split up if I include more than one hostname. This works fine, but it is sequential, and runtime is a few minutes. I started thinking about running my clones in parallel, after reading the docs I determined Job Slicing is the correct route to make this happen. However I may be misunderstanding how Slices work with extra vars, and maybe this isn’t possible with how I have my playbook currently written.

Is it possible to make a slice for each iteration of a loop based on my “{{ vm\_name }}” extra var? If not, is there an alternative way to achieve this goal, a workflow perhaps?

```auto
---
- name: Clone VM's from template and configure with cloud-init
  hosts: localhost
  gather_facts: false
  vars:
    working_node: '{{ pve_node }}'

  module_defaults:
    proxmox_kvm:
      api_user: '{{ lookup("env", "PROXMOX_USER") }}'
      api_password: '{{ lookup("env", "PROXMOX_PASSWORD") }}'
      api_host: '{{ lookup("env", "PROXMOX_HOST") }}'

  tasks:
    - name: Loop through vm_name
      include_tasks: ../../pve/clone-template.yml
      loop: '{{ vm_name.split(",") }}'

```

Thanks in advance and happy holidays!

---

<div class="post-metadata">

**Author:** ![matteoclc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matteoclc/32/7020_2.png) [@matteoclc](https://forum.ansible.com/u/matteoclc)\
**Post date:** [December 17, 2024, 5:51pm UTC](https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213/2 "2024-12-17T17:51:56Z")

</div>

Hi, a possible solution is using the async option and poll=0, have a look here:  
[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_async.html#run-tasks-concurrently-poll-0](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_async.html#run-tasks-concurrently-poll-0)

a quick example is:

```auto
---

- hosts: localhost
  connection: local
  gather_facts: false
  vars:
    list:
      - one
      - two
      - three
  tasks:
    - name: Test task
      ansible.builtin.shell: /bin/sleep 3 && echo {{ item }}
      async: 45
      poll: 0
      loop: "{{ list }}"
      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

```

I think it should work for your case

---

<div class="post-metadata">

**Author:** ![sirsikes777](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sirsikes777](https://forum.ansible.com/u/sirsikes777)\
**Post date:** [December 18, 2024, 5:14pm UTC](https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213/3 "2024-12-18T17:14:31Z")

</div>

I had looked at async, because of my use of include\_tasks and the structure of the playbook it was going to take a bit of a rewrite. Well I got it rewritten last night and everything is working great! The async status checks also allowed me to ditch some pauses I had in between proxmox\_kvm module tasks saving even more time. Appreciate the suggestion and thank you very much. I went from 7 minutes to spin up 5 VM’s to 58 seconds for 10. 🫡

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 17, 2025, 5:15pm UTC](https://forum.ansible.com/t/job-slicing-extra-vars-awx/39213/4 "2025-01-17T17:15:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
