---
- name: Verify loop file isn't mounted
  fail:
    msg: "Loop file is already mounted"
  when: loop_mount_location in (ansible_mounts | map(attribute='mount'))

- name: Create loop file
  command: "dd if=/dev/zero of={{ loop_file_location }} bs=1M count={{ loop_size_MiB }}"

- name: Make ext4 filesystem on target
  command: "mkfs.ext4 -F {{ loop_file_location }}"
  become: yes
  when: loop_filesystem == 'ext4'

- name: Make fat filesystem on target
  command: "mkfs.fat -F32 {{ loop_file_location }}"
  become: yes
  when: loop_filesystem == 'fat32'
