|
121 | 121 | # every cert in combined-ca-bundle, retrying until it appears. |
122 | 122 | # ------------------------------------------------------------------------- |
123 | 123 | - name: Wait for leaf region CA to appear in combined-ca-bundle |
124 | | - ansible.builtin.shell: | |
125 | | - set -euo pipefail |
126 | | - TMPDIR=$(mktemp -d) |
127 | | - trap "rm -rf $TMPDIR" EXIT |
128 | | -
|
129 | | - echo "{{ _leaf_certs.results[0].resources[0].data['tls.crt'] }}" | \ |
130 | | - base64 -d > "$TMPDIR/leaf-ca.crt" |
131 | | - FINGERPRINT=$(openssl x509 -noout -fingerprint -in "$TMPDIR/leaf-ca.crt" \ |
132 | | - | cut -d= -f2) |
133 | | -
|
134 | | - oc get secret combined-ca-bundle \ |
135 | | - -n {{ central_namespace }} \ |
136 | | - -o jsonpath='{.data.tls-ca-bundle\.pem}' \ |
137 | | - | base64 -d > "$TMPDIR/bundle.pem" |
138 | | -
|
139 | | - python3 - "$FINGERPRINT" "$TMPDIR/bundle.pem" <<'PYEOF' |
140 | | - import sys, subprocess, re |
141 | | - target, bundle_file = sys.argv[1], sys.argv[2] |
142 | | - bundle = open(bundle_file).read() |
143 | | - certs = re.findall( |
144 | | - r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----', |
145 | | - bundle, re.DOTALL |
| 124 | + kubernetes.core.k8s_info: |
| 125 | + api_version: v1 |
| 126 | + kind: Secret |
| 127 | + namespace: "{{ central_namespace }}" |
| 128 | + name: combined-ca-bundle |
| 129 | + register: _combined_bundle |
| 130 | + until: >- |
| 131 | + (_combined_bundle.resources | length > 0) and |
| 132 | + ( |
| 133 | + _leaf_certs.results[0].resources[0].data['tls.crt'] | b64decode |
| 134 | + in |
| 135 | + (_combined_bundle.resources | first).data['tls-ca-bundle.pem'] | b64decode |
146 | 136 | ) |
147 | | - for cert in certs: |
148 | | - r = subprocess.run( |
149 | | - ['openssl', 'x509', '-noout', '-fingerprint'], |
150 | | - input=cert.encode(), capture_output=True |
151 | | - ) |
152 | | - if target in r.stdout.decode(): |
153 | | - sys.exit(0) |
154 | | - sys.exit(1) |
155 | | - PYEOF |
156 | | - args: |
157 | | - executable: /bin/bash |
158 | | - register: _ca_reconciled |
159 | | - until: _ca_reconciled.rc == 0 |
160 | 137 | retries: 30 |
161 | 138 | delay: 10 |
162 | 139 | changed_when: false |
0 commit comments