Ansible Galaxy collection repository.
Easily chunk your array to the size you want.
While trying to remove objects from a S3 bucket, DeleteObjects directive limit to 1000 objects per call. Since the ListObjectsV2 return the whole list of objects, I needed to chunk my objects list in smaller (in that case 5*1000 objects).
Install it via ansible-galaxy (recommended):
ansible-galaxy collection install marmorag.chunk
- name: your list
set_fact:
your_list: [0,1,2,3,4]
- name: chunk list
chunk:
src: "{{ your_list }}"
size: 2
register: chunked
- name: process
command: "echo {{ item }}"
loop: "{{ chunked.chunks }}"
Output format :
{
"chunks": [[0,1], [2,3], [4]],
"changed": true,
"failed": false
}