|
| 1 | + # check if Cluster Health is good |
| 2 | +- name: Check if cluster operators and nodes are healthy |
| 3 | + include_role: |
| 4 | + name: check-cluster-health |
| 5 | + |
| 6 | +- name: Check if cso_namespace is defined, and set default if not |
| 7 | + set_fact: |
| 8 | + cso_namespace: "{{ cso_namespace | default('quay-registry') }}" # Set default namespace if not defined |
| 9 | + |
| 10 | +- name: Create a target namespace |
| 11 | + kubernetes.core.k8s: |
| 12 | + state: present |
| 13 | + definition: |
| 14 | + apiVersion: v1 |
| 15 | + kind: Namespace |
| 16 | + metadata: |
| 17 | + name: "{{ cso_namespace }}" |
| 18 | + when: cso_namespace is defined |
| 19 | + |
| 20 | +# Custom ImageContentSourcePolicy and CatalogSource |
| 21 | +- name: Create ImageContentSourcePolicy and CatalogSource |
| 22 | + block: |
| 23 | + - name: Include the global-secret-update role |
| 24 | + include_role: |
| 25 | + name: global-secret-update |
| 26 | + |
| 27 | + - name: Include role to create ImageContentSourcePolicy and CatalogSource |
| 28 | + include_role: |
| 29 | + name: set-custom-catalogsource |
| 30 | + vars: |
| 31 | + custom_catalogsource_name: "{{ cso_catalogsource_name }}" |
| 32 | + custom_catalogsource_display_name: "Custom CSO CatalogSource" |
| 33 | + custom_catalogsource_image: "{{ cso_catalogsource_image }}" |
| 34 | + when: cso_catalogsource_image is defined or cso_catalogsource_image != '' and cso_catalogsource_image != None |
| 35 | + |
| 36 | +- name: Use default CatalogSource if no custom image is provided |
| 37 | + set_fact: |
| 38 | + cso_catalogsource_name: "redhat-operators" |
| 39 | + when: cso_catalogsource_image is undefined or cso_catalogsource_image == '' or cso_catalogsource_image == None |
| 40 | + |
| 41 | +- name: Verify creation of Catsrc |
| 42 | + shell: oc get catsrc -A | grep "{{ cso_catalogsource_name }}" |
| 43 | + register: catsrc |
| 44 | + until: catsrc.stdout|int == 0 and catsrc.stderr == "" |
| 45 | + retries: 10 |
| 46 | + delay: 30 |
| 47 | + |
| 48 | +- name: Check if CSO CatalogSource exists and is READY |
| 49 | + shell: > |
| 50 | + oc get catalogsource {{ cso_catalogsource_name }} -n openshift-marketplace -o jsonpath='{.status.connectionState.lastObservedState}' |
| 51 | + register: cso_catsrc_check |
| 52 | + retries: 10 |
| 53 | + delay: 15 |
| 54 | + until: cso_catsrc_check.rc == 0 |
| 55 | + changed_when: false |
| 56 | + failed_when: cso_catsrc_check.rc != 0 |
| 57 | + |
| 58 | +- name: Debug output for CSO CatalogSource check |
| 59 | + debug: |
| 60 | + msg: "CSO CatalogSource '{{ cso_catalogsource_name }}' is present and in Ready state." |
| 61 | + |
| 62 | +- name: Create OperatorGroup for CSO |
| 63 | + k8s: |
| 64 | + state: present |
| 65 | + definition: |
| 66 | + apiVersion: operators.coreos.com/v1 |
| 67 | + kind: OperatorGroup |
| 68 | + metadata: |
| 69 | + name: cso-operator-group |
| 70 | + namespace: "{{ cso_namespace }}" |
| 71 | + spec: {} |
| 72 | + |
| 73 | +- name: Create CSO Operator Subscription |
| 74 | + k8s: |
| 75 | + state: present |
| 76 | + definition: |
| 77 | + apiVersion: operators.coreos.com/v1alpha1 |
| 78 | + kind: Subscription |
| 79 | + metadata: |
| 80 | + name: cso-operator |
| 81 | + namespace: "{{ cso_namespace }}" |
| 82 | + spec: |
| 83 | + channel: "{{ cso_operator_channel }}" |
| 84 | + name: cso-operator |
| 85 | + source: "{{ cso_catalogsource_name }}" |
| 86 | + sourceNamespace: openshift-marketplace |
| 87 | + installPlanApproval: Automatic |
| 88 | + |
| 89 | +- name: Check if cso Operator CSV is in 'Succeeded' phase |
| 90 | + shell: | |
| 91 | + oc get csv -n {{ cso_namespace }} --no-headers | grep cso-operator | grep Succeeded |
| 92 | + register: csv_status |
| 93 | + retries: 10 |
| 94 | + delay: 30 |
| 95 | + until: csv_status.stdout != "" and csv_status.stderr == "" |
| 96 | + failed_when: csv_status.rc != 0 |
| 97 | + |
| 98 | +- name: Debug cso operator CSV status |
| 99 | + debug: |
| 100 | + msg: "Container Security Operator CSV has successfully reached 'Succeeded' state." |
| 101 | + |
0 commit comments