# ansible tasks for installing libblockdev dependencies,
# see install-test-dependencies.yml for usage

---
####### Fedora
- name: Install basic build tools (Fedora)
  package:
    state: present
    name:
      - gcc
      - make
      - libtool
      - autoconf
      - automake
  when: ansible_distribution == 'Fedora'

- name: Install dnf-plugins-core for dnf builddep (Fedora)
  package: name=dnf-plugins-core state=present
  when: ansible_distribution == 'Fedora'

- name: Install build dependencies (Fedora)
  command: "dnf -y builddep libblockdev --nogpgcheck"
  when: ansible_distribution == 'Fedora'

- name: Install build dependencies not covered by dnf builddep (Fedora)
  package:
    state: present
    name:
      - libfdisk-devel
      - keyutils-libs-devel
      - libnvme-devel
      - e2fsprogs-devel
      - json-glib-devel
      - libatasmart-devel
      - libyaml-devel
  when: ansible_distribution == 'Fedora'

- name: Install test dependencies (Fedora)
  package:
    state: present
    name:
      - btrfs-progs
      - cryptsetup
      - device-mapper-multipath
      - dosfstools
      - e2fsprogs
      - exfatprogs
      - f2fs-tools
      - glibc-all-langpacks
      - kernel-modules-extra
      - lvm2-dbusd
      - mdadm
      - ndctl
      - nilfs-utils
      - nss-tools
      - ntfsprogs
      - nvme-cli
      - nvmetcli
      - python3-bytesize
      - python3-dbus
      - python3-packaging
      - python3-pylint
      - python3-yaml
      - smartmontools
      - targetcli
      - udftools
      - vdo
      - volume_key
      - xfsprogs
  when: ansible_distribution == 'Fedora' and test_dependencies|bool

####### CentOS
- name: Install basic build tools (CentOS)
  package:
    state: present
    name:
      - gcc
      - make
      - libtool
      - autoconf
      - automake
  when: ansible_distribution == 'CentOS'

- name: Install dnf-plugins-core for dnf builddep (CentOS)
  package: name=dnf-plugins-core state=present
  when: ansible_distribution == 'CentOS'

- name: Install build dependencies (CentOS)
  command: "dnf -y builddep libblockdev --nogpgcheck"
  when: ansible_distribution == 'CentOS'

- name: Install build dependencies not covered by dnf builddep (CentOS)
  package:
    state: present
    name:
      - libfdisk-devel
      - keyutils-libs-devel
      - libnvme-devel
      - e2fsprogs-devel
      - json-glib-devel
      - libatasmart-devel
      - libyaml-devel
  when: ansible_distribution == 'CentOS'

- name: Install test dependencies (CentOS)
  package:
    state: present
    name:
      - cryptsetup
      - device-mapper-multipath
      - dosfstools
      - e2fsprogs
      - glibc-all-langpacks
      - lvm2-dbusd
      - mdadm
      - ndctl
      - nss-tools
      - nvme-cli
      - nvmetcli
      - python3-bytesize
      - python3-dbus
      - python3-packaging
      - python3-yaml
      - smartmontools
      - targetcli
      - vdo
      - volume_key
      - xfsprogs
  when: ansible_distribution == 'CentOS' and test_dependencies|bool

- name: Install pylint using pip (CentOS)
  pip:
    name: ['pylint']
    extra_args: --break-system-packages
  when: ansible_distribution == 'CentOS' and test_dependencies|bool

####### Debian/Ubuntu
- name: Update apt cache (Debian/Ubuntu)
  apt:
    update_cache: yes
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install basic build tools (Debian/Ubuntu)
  package:
    state: present
    name:
      - gcc
      - make
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Add source repositories (Debian/Ubuntu)
  shell: "grep '^deb ' /etc/apt/sources.list | perl -pe 's/deb /deb-src /' >> /etc/apt/sources.list"
  when: ansible_distribution == 'Debian' or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version < '24')

- name: Add source repositories (Debian/Ubuntu)
  shell: "sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources"
  when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '24'

- name: Update apt cache (Debian/Ubuntu)
  apt:
    update_cache: yes
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install build dependencies (Debian/Ubuntu)
  apt:
    name: libblockdev
    state: build-dep
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install build dependencies not covered by apt build-dep (Debian/Ubuntu)
  package:
    state: present
    name:
      - libfdisk-dev
      - libkeyutils-dev
      - libext2fs-dev
      - libjson-glib-dev
      - libatasmart-dev
      - libyaml-dev
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install test dependencies (Debian/Ubuntu)
  package:
    state: present
    name:
      - btrfs-progs
      - cryptsetup
      - dosfstools
      - e2fsprogs
      - exfatprogs
      - f2fs-tools
      - libnss3-tools
      - locales-all
      - lvm2-dbusd
      - mdadm
      - ndctl
      - nilfs-tools
      - ntfs-3g
      - pylint
      - python3-bytesize
      - python3-packaging
      - python3-pydbus
      - python3-yaml
      - smartmontools
      - targetcli-fb
      - udftools
      - volume-key
      - xfsprogs
  when: (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') and test_dependencies|bool

- name: Install vdo test dependencies (Debian/Ubuntu 64bit)
  package:
    state: present
    name:
      - vdo
  when: (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') and test_dependencies|bool and ansible_architecture != 'i386'

####### Common actions

- name: Start LVM DBus service
  service: name=lvm2-lvmdbusd state=started
  ignore_errors: yes
  when: test_dependencies|bool
