---
- name: Get cluster version
  kubernetes.core.k8s_info:
    api_version: config.openshift.io/v1
    kind: ClusterVersion
    name: version
  register: cluster_version

- name: Set OCP version fact
  ansible.builtin.set_fact:
    ocp_version: "{{ cluster_version.resources[0].status.desired.version }}"

- name: Create temporary directory for s390x artifacts
  ansible.builtin.tempfile:
    state: directory
    suffix: s390x
  register: temp_dir

# maybe we have to log into quay first here

- name: Extract s390x release tools
  ansible.builtin.command:
    cmd: "oc adm release extract --tools quay.io/openshift-release-dev/ocp-release:{{ ocp_version }}-s390x"
    chdir: "{{ temp_dir.path }}"

- name: Install coreos-installer
  ansible.builtin.package:
    name: coreos-installer
    state: present
  become: true

- name: Get cluster infrastructure details
  kubernetes.core.k8s_info:
    api_version: config.openshift.io/v1
    kind: Infrastructure
    name: cluster
  register: cluster_infrastructure

- name: Generate worker ignition config
  ansible.builtin.command:
    cmd: "openshift-install create worker-ignition"
    chdir: "{{ temp_dir.path }}"

- name: Create ISO for s390x nodes
  ansible.builtin.command:
    cmd: >-
      coreos-installer iso customize
      --dest-ignition {{ temp_dir.path }}/worker.ign
      --output {{ temp_dir.path }}/s390x-worker.iso
      {{ temp_dir.path }}/rhcos-live.s390x.iso 