# This is a simple ansible playbook for installing packages needed by the
# libbytesize test suite.
# You can do this by using 'make install-requires' or manually using
# 'ansible-playbook -K -i "localhost," -c local install-test-dependencies.yml'
# Currently only Fedora and Debian/Ubuntu are supported by this playbook.

---
- hosts: all
  become: true

  tasks:
  - name: Install basic build tools (Fedora)
    package: name={{item}} state=present
    with_items:
      - 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 libbytesize --nogpgcheck"
    args:
      warn: false
    when: ansible_distribution == 'Fedora'

  - name: Install test dependencies (Fedora)
    package: name={{item}} state=present
    with_items:
      - glibc-all-langpacks
      - python3-polib
      - python3-six
      - python3-pocketlint
      - python3-pylint
      - python3-pycodestyle
    when: ansible_distribution == 'Fedora'

  - name: Install basic build tools (Debian/Ubuntu)
    package: name={{item}} state=present
    with_items:
      - 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'

  - 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: libbytesize
      state: build-dep
    when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

  - name: Install test dependencies (Debian/Ubuntu)
    package: name={{item}} state=present
    with_items:
      - locales-all
      - python3-polib
      - python3-six
      - python3-pip
      - pycodestyle
      - pylint
    when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

  - name: Install pocketlint using pip on Debian/Ubuntu
    pip:
      name: ['pocketlint']
      executable: pip3
    when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
