- name: Set package prefix
  set_fact:
    rhel_package_prefix: >-
        {%- if linux_distro in ['centos7','redhat7'] -%}
            el7
        {%- elif linux_distro in ['centos8','redhat8'] -%}
            el8
        {%- endif -%}

- name: Find erlang package
  become: yes
  find:
    paths: "{{ xray_home }}/app/third-party/rabbitmq/"
    patterns: "^(esl-)?erlang.+{{ rhel_package_prefix }}.+\\.rpm$"
    use_regex: yes
    file_type: file
  register: check_erlang_package_result

- name: Set erlang package file name
  set_fact:
    xray_erlang_package: "{{ check_erlang_package_result.files[0].path }}"
  when: check_erlang_package_result.matched > 0

- name: Install erlang package
  become: yes
  yum:
    name: "{{ xray_erlang_package }}"
    state: present
  vars:
    ansible_python_interpreter: "{{ yum_python_interpreter }}"
  register: install_erlang_package_result
  when: check_erlang_package_result.matched > 0
