--- - name: Rebuild Behemoth Containers hosts: all become: yes tasks: - name: Get Build File Listing shell: "ls -lR /opt/containers/*/build.sh | cut -b 41- | cut -d '/' -f 1-4" register: behemoth_container_output - name: Get Name Listing shell: "ls -lR /opt/containers/*/build.sh | cut -b 41- | cut -d '/' -f 4" register: folder_name_output - name: Combine folder names and paths into a list of dictionaries set_fact: behemoth_containers: "{{ behemoth_containers | default([]) + [{'folder_name': item[0], 'folder_path': item[1]}] }}" loop: "{{ folder_name_output.stdout_lines | zip(behemoth_container_output.stdout_lines) }}" loop_control: label: "{{ item[0] }}" - name: Build images docker_image: name: "{{ item.folder_name }}" source: build build: path: "{{ item.folder_path }}" state: present tag: latest loop: "{{ behemoth_containers }}" register: build_output ignore_errors: true - name: Output Debug debug: msg: - "Container name: {{item.item.folder_name}}" - "Build Environment: {{item.item.folder_path}}" - "Container Size: {{ (item.image.Size / 1048576 | float) | round(2) }} MB" - "{{ 'Image updated' if item.changed else 'No Change Made' }}" - "{{ 'Warning: Failure Detected' if item.failed else 'No Failure Detected' }}" loop: "{{ build_output.results }}" loop_control: label: "{{ item.item.folder_name }}" ...