---
- name: setup loopback device in staging environment
  become: true
  block:
    - name: set docker vars
      set_fact:
        docker_device: /dev/loop0
        docker_partition: /dev/mapper/loop0p1

    - name: Create loop device
      command: "mknod -m640 {{ docker_device }} b 7 0"
      args:
        creates: "{{ docker_device }}"

    - name: Create empty loop file
      command: dd if=/dev/zero of=/var/docker_device.img bs=100M count=1
      args:
        creates: /var/docker_device.img

    - name: Check existing association
      command: losetup
      register: losetup_list

    - name: Associate file to device
      command: losetup -P /dev/loop0 /var/docker_device.img
      when: "'/dev/loop0' not in losetup_list.stdout"

---
- name: setup loopback device in staging environment
  become: true
  block:
    - name: set docker vars
      set_fact:
        docker_device: /dev/loop0
        docker_partition: /dev/mapper/loop0p1

    - name: Modeprobe loop device
      command: "modprobe loop"

    - name: Check loop is loaded
      shell: "lsmod | grep loop"
      register: lsmod_out

    - name: Fail if loop is not loaded
      fail:
        msg: "Loop kernel module is not loaded"
      when: "'loop' not in lsmod_out.stdout"

    - name: Create loop device
      command: "mknod -m640 {{ docker_device }} b 7 0"
      args:
        creates: "{{ docker_device }}"

    - name: Create empty loop file
      command: dd if=/dev/zero of=/var/docker_device.img bs=100M count=1
      args:
        creates: /var/docker_device.img

    - name: Check existing association
      command: losetup
      register: losetup_list

    - name: Associate file to device
      command: losetup -P /dev/loop0 /var/docker_device.img
      when: "'/dev/loop0' not in losetup_list.stdout"

Make sure loop kernel module is loaded
Make sure loop kernel module is loaded

Signed-off-by: Amol Kahat <95c009f1d717ce6482c2024394e62fb588cbf8d7@gmail.com>
Change-Id: I03a157f15baae6fcf24dfb91b404152c1b4088d1
