--- - name: Converge hosts: all become: true roles: - ansible-role-luks vars: luks_devices: - name: data_encrypted device: /dev/loop0 fstype: ext4 mount_point: /mnt/data_decrypted passphrase: secret pre_tasks: - name: Update apt cache ansible.builtin.apt: update_cache: true - name: Check if test.img exists ansible.builtin.stat: path: /tmp/test.img register: st - name: Create test.img ansible.builtin.command: dd if=/dev/zero of=/tmp/test.img bs=1M count=100 when: not st.stat.exists - name: Create loop device ansible.builtin.command: losetup -fP /tmp/test.img when: not st.stat.exists