# SPDX-License-Identifier: MIT
# This task configures test systems for testing in the CI environment.
# Only use this task for testing.
# This task file resides in `tasks/` so that it can be used from other roles
# with `include_role` with `tasks_from: filename` directly without the need to
# provide a relative path. Providing relative path is problematic with
# collections.
---
- name: Load softdog module for SBD to have at least one watchdog
  command: modprobe softdog
  changed_when: true
  # do not load if sbd tests are run (loads module instead)
  when: not (__test_disable_modprobe | d(false))

- name: Create backing files for SBD devices
  tempfile:
    state: file
    suffix: _ha_cluster_tests
  register: __test_sbd_tmpfile

- name: Initialize backing files for SBD devices
  command:
    cmd: dd if=/dev/zero of={{ __test_sbd_tmpfile.path | quote }} bs=1M count=10
  changed_when: true

- name: Mount SBD devices
  command:
    cmd: losetup --show --find {{ __test_sbd_tmpfile.path | quote }}
  register: __test_sbd_mount
  changed_when: true
