
  - include: fedora_init.yml

  - include: debian_init.yml

  - name: Force HTTP repository for old debian versions without HTTPS support
    set_fact:
      base_open_build_url: "{{ base_open_build_url_http }}"
    when: (ansible_distribution == "Debian" and ansible_distribution_major_version|int < 11) or
          (ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int < 22)

  - name: Remove {{ base_open_build_url }} key (and add later) on every upgrade, as expiration date is quite short (2 months).
    apt_key: id=94A63987 state=absent
    when: ansible_distribution == "Debian"

  - file: path=/etc/apt/sources.list.d/re6stnet.list state=absent
    when: ansible_distribution == "Debian"

  - name: Install Debian 11 repository key
    apt_key: url={{ base_open_build_url }}/Debian_11/Release.key state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "11"

  - name: Install Debian 10 repository key
    apt_key: url={{ base_open_build_url }}/Debian_10/Release.key state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "10"

  - name: Install Debian 9 repository key
    apt_key: url={{ base_open_build_url }}/Debian_9.0/Release.key state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "9"

  - name: Install Debian 8 repository key
    apt_key: url={{ base_open_build_url }}/Debian_8.0/Release.key state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "8"

  - name: Install Debian 11 repository
    apt_repository: repo='deb {{ base_open_build_url }}/Debian_11/ ./' state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "11"

  - name: Install Debian 10 repository
    apt_repository: repo='deb {{ base_open_build_url }}/Debian_10/ ./' state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "10"

  - name: Install Debian 9 repository
    apt_repository: repo='deb {{ base_open_build_url }}/Debian_9.0/ ./' state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "9"

  - name: Install Debian 8 repository
    apt_repository: repo='deb {{ base_open_build_url }}/Debian_8.0/ ./' state=present
    when: ansible_distribution == "Debian" and ansible_distribution_major_version == "8"

  - name: Install Ubuntu 14.04 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_14.04/Release.key state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "14.04"

  - name: Install Ubuntu 14.04 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_14.04/ ./' state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "14.04" 

  - name: Install Ubuntu 14.04 repository key (Linuxmint 17.2)
    apt_key: url={{ base_open_build_url }}/xUbuntu_14.04/Release.key state=present
    when: ansible_distribution == "Linuxmint" and ansible_distribution_version == "17.2"

  - name: Install Ubuntu 14.04 repository (Linuxmint 17.2)
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_14.04/ ./' state=present
    when: ansible_distribution == "Linuxmint" and ansible_distribution_version == "17.2"

  - name: Install Ubuntu 16.04 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_16.04/Release.key state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04"

  - name: Install Ubuntu 16.04 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_16.04/ ./' state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04" 

  - name: Install Ubuntu 18.04 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_18.04/Release.key state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "18.04"

  - name: Install Ubuntu 18.04 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_18.04/ ./' state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "18.04"

  - name: Install Ubuntu 19.10 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_19.10/Release.key state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "19.10"

  - name: Install Ubuntu 19.10 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_19.10/ ./' state=present
    when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "19.10"

  - name: Install Ubuntu 20.04 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_20.04/Release.key state=present
    when: (ansible_distribution == "Ubuntu" and ansible_distribution_version == "20.04") or (ansible_lsb.codename == "kylin" and ansible_lsb.major_release == "v10")

  - name: Install Ubuntu 20.04 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_20.04/ ./' state=present
    when: (ansible_distribution == "Ubuntu" and ansible_distribution_version == "20.04") or (ansible_lsb.codename == "kylin" and ansible_lsb.major_release == "v10")

  - name: Install Ubuntu 22.04 repository key
    apt_key: url={{ base_open_build_url }}/xUbuntu_22.04/Release.key state=present
    when: (ansible_distribution == "Ubuntu" and ansible_distribution_version == "22.04") or (ansible_distribution == "Linux Mint" and ansible_distribution_major_version == "21")

  - name: Install Ubuntu 22.04 repository
    apt_repository: repo='deb {{ base_open_build_url }}/xUbuntu_22.04/ ./' state=present
    when: (ansible_distribution == "Ubuntu" and ansible_distribution_version == "22.04") or (ansible_distribution == "Linux Mint" and ansible_distribution_major_version == "21")

  - name: Install CentOS 7 Repository
    get_url: url={{ base_open_build_url }}/CentOS_7/home:VIFIBnexedi.repo dest=/etc/yum.repos.d/slapos.repo mode=0440
    when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"

  - name: Install CentOS 7 RPM Key
    # workarounded with https://github.com/marbu/ansible-modules-core-issue-1853-reproducer/commit/41727b465533717015d8d55904c5a102fe248bc4
    # for https://github.com/ansible/ansible-modules-core/issues/1853
    rpm_key: state=present key=roles/repository/files/VIFIBNexedi_CentOS_7.key
    when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"

  - name: Install OpenSuse Leap 15 RPM Key
    rpm_key: state=present key={{ base_open_build_url }}/openSUSE_Leap_15.1/repodata/repomd.xml.key
    when: ansible_distribution == "Suse" and ansible_distribution_major_version == "15"

  - name: Install OpenSuse Leap 15 repository
    get_url: url={{ base_open_build_url }}/openSUSE_Leap_15.1/home:VIFIBnexedi.repo dest=/etc/zypp/repos.d/home_VIFIBnexedi.repo mode=0440
    when: ansible_os_family == "Suse" and ansible_distribution_major_version == "15"

  - name: Install Fedora 32 repository
    yum_repository: name='home_VIFIBnexedi' description='SlapOS-Node (Fedora_32)' baseurl='https://download.opensuse.org/repositories/home:/VIFIBnexedi/Fedora_32/' gpgkey='https://download.opensuse.org/repositories/home:/VIFIBnexedi/Fedora_32/repodata/repomd.xml.key' gpgcheck=yes enabled=yes
    when: ansible_distribution == "Fedora" and ansible_distribution_major_version == "32"
