---
- name: install the lvm2 package
  dnf: state=present name=lvm2

- name: early stat for the ext4 filesystem
  stat: path=/dev/disk/by-label/copr-repo
  register: stat_repo_fs_early
  tags: mdadm

- name: VG on two RAIDs
  tags: mdadm
  when: not stat_repo_fs_early.stat.exists
  block:
    - name: install LVM and RAID utilities
      package:
        name:
          - lvm2
          - mdadm
      tags:
        - mdadm

    - name: stat the raid volumes
      stat:
        path: "/dev/disk/by-id/{{ item }}"
      register: stat_raid
      loop:
        - "{{ copr_backend_data_raid10_volumes }}"
        - "{{ copr_backend_data_2_raid1_volumes }}"

    - name: fail if raid volumes do not exist
      debug: msg=checked
      failed_when: not item.stat.exists
      loop: "{{ stat_raid.results }}"

    - name: stat the ext4 filesystem
      stat: path=/dev/disk/by-label/copr-repo
      register: stat_repo_fs

    - name: scan the raid volumes
      when: not stat_repo_fs.stat.exists
      shell: mdadm --assemble --scan && sleep 5

    - name: stat the ext4 filesystem
      stat: path=/dev/disk/by-label/copr-repo
      register: stat_repo_fs

    - name: fail if ext4 filesystem is not found by devmapper
      debug: msg=checked
      failed_when: not stat_repo_fs.stat.exists

- name: decrease the RAID checks frequency in AWS
  tags:
    - mdadm
    - raid
    - raid_check
  when: datacenter == 'aws'
  block:
    - name: install the drop-in raid-check.timer override
      copy:
        dest: /etc/systemd/system/raid-check.timer
        content: |
          [Unit]
          Description=Monthly RAID health check in AWS

          [Timer]
          OnCalendar=Sat *-*-8..14 01:00:00
          Persistent=true
          AccuracySec=24h

          [Install]
          WantedBy=timers.target
      notify: systemctl daemon-reload

- name: prepare mount point
  file: state=directory path=/var/lib/copr/public_html

- name: mount up disk of copr repo
  mount: name=/var/lib/copr/public_html src='LABEL=copr-repo' fstype=ext4 state=mounted

- name: mount /tmp/
  mount: name=/tmp src='tmpfs' fstype=tmpfs state=mounted
