#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
---

- name: Creating DSU directory
  file:
    path: "{{ dsu_folder_dest }}"
    state: directory
    mode: "{{ dsu_folder_dest_mode }}"

- name: Download bootstrap.cgi
  get_url:
    url: "{{ bootstrap_repo_url }}"
    dest: "{{ dsu_folder_dest }}"
  register: bootstrap_repo_result
  until: bootstrap_repo_result is not failed
  retries: 20

- name: Execute bootstrap.cgi
  shell: >
    set -o pipefail && \
    echo "y" | bash {{ dsu_folder_dest }}/bootstrap.cgi
  changed_when: true
  register: bootstrap_execution_result
  failed_when: "'FAILED' in bootstrap_execution_result.stderr"

- name: Download dell-omnia-system-update.rpm
  get_url:
    url: "{{ dsu_rpm_url }}"
    dest: "{{ dsu_folder_dest }}"
  register: dsu_rpm_result
  until: dsu_rpm_result is not failed
  retries: 20

- name: Install DSU
  command: dnf install "{{ dsu_folder_dest }}/{{ dsu_rpm_file }}" -y
  changed_when: true