diff --git a/playbooks/roles/ocp-upgrade/tasks/main.yaml b/playbooks/roles/ocp-upgrade/tasks/main.yaml index c9438bf6..391d994f 100644 --- a/playbooks/roles/ocp-upgrade/tasks/main.yaml +++ b/playbooks/roles/ocp-upgrade/tasks/main.yaml @@ -1,5 +1,23 @@ --- +- name: Fetch cluster operators details + shell: "oc get co" + register: oplog + until: "'AVAILABLE' in oplog.stdout" + retries: 3 + delay: 3 + +- name: Process cluster operators details + shell: | + echo "{{ oplog.stdout }}" | awk '/PROGRESSING/,EOF {print $4}' | grep 'True' | wc -l + echo "{{ oplog.stdout }}" | awk '/DEGRADED/,EOF {print $5}' | grep 'True' | wc -l + register: opcount + +- name: Fail upgrade process incase cluster state is unhealthy + fail: + msg: The current cluster state is unhealthy, upgrading it is not recommended. Please run 'oc get co' command for more details or try upgrade after sometime. + when: opcount.stdout_lines[0]|int > 0 or opcount.stdout_lines[1]|int > 0 + - name: Upgrade ocp to a stable version block: - name: Set upgrade channel