---
- name: Copy files
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "/var/tmp/"
    mode: "0644"
  register: powerflex_common_file
  with_fileglob:
    - "{{ powerflex_common_file_install_location }}/*{{ file_glob_name }}*.rpm"
    - "{{ powerflex_common_file_install_location }}/{{ file_gpg_name }}*"

- name: List the rpm file
  register: powerflex_common_package_file
  ansible.builtin.find:
    paths: "/var/tmp/"
    patterns: "*{{ file_glob_name }}*.rpm"

- name: List the rpm gpg file
  register: powerflex_common_package_gpg
  ansible.builtin.find:
    paths: "/var/tmp/"
    patterns: "{{ file_gpg_name }}*"

- name: Import gpg key
  ansible.builtin.rpm_key:
    state: present
    key: "{{ powerflex_common_package_gpg.files[0].path }}"
  when: powerflex_common_package_gpg.files | length > 0

- name: Install package
  register: powerflex_common_install_package_output
  environment: "{{ powerflex_role_environment }}"
  ansible.builtin.package:
    name: "{{ powerflex_common_package_file.files[0].path }}"
    state: "present"
    disable_gpg_check: "{{ powerflex_gateway_disable_gpg_check | default(false) }}"
