diff --git a/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-cnv-operator.yml b/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-cnv-operator.yml index 20227d2..47a6014 100644 --- a/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-cnv-operator.yml +++ b/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-cnv-operator.yml @@ -35,10 +35,6 @@ sourceNamespace: openshift-marketplace name: kubevirt-hyperconverged -- name: Wait - ansible.builtin.pause: - seconds: 300 - - name: Get Install Plan Name from Subscription retries: 10 delay: 10 @@ -76,10 +72,6 @@ msg: "Install Plan is not Complete after the specified wait period." when: __sap_hypervisor_node_preconfigure_register_wait_for_installplan.resources[0].status.phase != "Complete" -- name: Wait - ansible.builtin.pause: - seconds: 300 - - name: Create CNV HyperConverged kubernetes.core.k8s: state: present @@ -89,8 +81,35 @@ metadata: name: kubevirt-hyperconverged namespace: "{{ sap_hypervisor_node_preconfigure_ocpv_namespace }}" - spec: -- name: Wait - ansible.builtin.pause: - seconds: 300 +- name: Retrieve HyperConverged Status + kubernetes.core.k8s_info: + api_version: hco.kubevirt.io/v1beta1 + kind: HyperConverged + name: kubevirt-hyperconverged + namespace: "{{ sap_hypervisor_node_preconfigure_ocpv_namespace }}" + register: hyperconverged_status + until: > + {{ + (hyperconverged_status.resources[0].status.conditions | + selectattr('type', 'equalto', 'Available') | + selectattr('status', 'equalto', 'True') | + list | length > 0) | bool + }} + retries: 60 + delay: 10 + +- name: Set HyperConverged Available Fact + ansible.builtin.set_fact: + hyperconverged_available: >- + {{ + (hyperconverged_status.resources[0].status.conditions | + selectattr('type', 'equalto', 'Available') | + selectattr('status', 'equalto', 'True') | + list | length > 0) | bool + }} + +- name: Fail if HyperConverged is not Available after waiting + ansible.builtin.fail: + msg: "HyperConverged is not Available after the specified wait period." + when: not hyperconverged_available diff --git a/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-nmstate-operator.yml b/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-nmstate-operator.yml index 5e1e4f4..12f493a 100644 --- a/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-nmstate-operator.yml +++ b/roles/sap_hypervisor_node_preconfigure/tasks/platform/redhat_ocp_virt/install-nmstate-operator.yml @@ -30,9 +30,16 @@ targetNamespaces: - openshift-nmstate -- name: Pause to give operator a chance to install - ansible.builtin.pause: - minutes: 2 +- name: Wait for nmstate OperatorGroup to be created + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1 + kind: OperatorGroup + name: openshift-nmstate-tn6k8 + namespace: openshift-nmstate + register: operatorgroup_status + retries: 30 + delay: 10 + until: operatorgroup_status.resources | length > 0 - name: Subscribe to the nmstate Operator kubernetes.core.k8s: @@ -52,9 +59,27 @@ source: redhat-operators sourceNamespace: openshift-marketplace -- name: Pause to give operator a chance to install - ansible.builtin.pause: - minutes: 5 +- name: Wait for Subscription to have an InstallPlan + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1alpha1 + kind: Subscription + name: kubernetes-nmstate-operator + namespace: openshift-nmstate + register: subscription_status + retries: 30 + delay: 10 + until: subscription_status.resources[0].status.installplan.name is defined + +- name: Wait for InstallPlan to complete + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1alpha1 + kind: InstallPlan + name: "{{ subscription_status.resources[0].status.installplan.name }}" + namespace: openshift-nmstate + register: installplan_status + retries: 30 + delay: 10 + until: installplan_status.resources[0].status.phase == "Complete" - name: Create instance of the nmstate operator kubernetes.core.k8s: @@ -65,6 +90,12 @@ metadata: name: nmstate -- name: Pause to give instance a chance to come up - ansible.builtin.pause: - minutes: 5 +- name: Wait for NMState instance to be created + kubernetes.core.k8s_info: + api_version: nmstate.io/v1 + kind: NMState + name: nmstate + register: nmstate_status + retries: 30 + delay: 10 + until: nmstate_status.resources | length > 0