# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# Analyse the repo list for this distribution selecting only those
# packages assigned to the active tier or 'all'.
- name:                                "1.3 Repository - Determine custom repos appropriate for tier {{ distribution_full_id }}"
  ansible.builtin.set_fact:
    custom_repos_for_tier:             "{{ custom_repos[distribution_full_id] |
                                             selectattr('tier', 'in', ['all', tier]) |
                                             list }}"

# Print list of matching repos if verbosity it 1 or greater
- name:                                "1.3 Repos: Print matching repos"
  ansible.builtin.debug:
    var:                               "{{ custom_repos_for_tier }}"
    verbosity:                         2
  when:
    - custom_repos_for_tier is defined
    - custom_repos_for_tier | length > 0

- name:                                "1.3 Repos: Add the repositories {{ ansible_os_family }}"
  ansible.builtin.dnf:
    name:                              "{{ item.url }}"
    state:                             "{{ item.state }}"
    disable_gpg_check:                 true
  loop:                                "{{ custom_repos_for_tier }}"
  register:                            custom_repos_zypresult
  ignore_errors:                       true

- name:                                "1.3 Repos: Add the repositories result"
  ansible.builtin.debug:
    var:                               custom_repos_zypresult
    verbosity:                         2

- name:                                "1.3 Repos: Add the HA repositories for RHEL"
  ansible.builtin.dnf:
    enablerepo:                        rhel-9-for-x86_64-highavailability-rpms
    disable_gpg_check:                 true
  changed_when:                        false
  when:
    - distribution_id in ['redhat9']
    - node_tier == 'ha'
