|
19 | 19 | msg: "'openshift_release_pull_spec' must be set by get_openshift_release_build_name.yml" |
20 | 20 | when: openshift_release_pull_spec is not defined or openshift_release_pull_spec == '' |
21 | 21 |
|
22 | | - - name: Extract pull secret from host cluster |
| 22 | + - name: Check if rhoso_kubeconfig file exists |
| 23 | + ansible.builtin.stat: |
| 24 | + path: "{{ rhoso_kubeconfig }}" |
| 25 | + register: _rhoso_kubeconfig_stat |
| 26 | + |
| 27 | + - name: Debug kubeconfig and environment info |
| 28 | + ansible.builtin.debug: |
| 29 | + msg: | |
| 30 | + rhoso_kubeconfig path: {{ rhoso_kubeconfig }} |
| 31 | + rhoso_kubeconfig exists: {{ _rhoso_kubeconfig_stat.stat.exists }} |
| 32 | + home_dir: {{ home_dir }} |
| 33 | + KUBECONFIG env: {{ lookup('ansible.builtin.env', 'KUBECONFIG', default='(not set)') }} |
| 34 | +
|
| 35 | + - name: Extract pull secret using rhoso_kubeconfig |
23 | 36 | ansible.builtin.shell: >- |
24 | 37 | set -o pipefail && |
25 | 38 | oc get secret pull-secret -n openshift-config |
26 | 39 | --kubeconfig={{ rhoso_kubeconfig }} |
27 | 40 | -o jsonpath='{.data.\.dockerconfigjson}' |
28 | 41 | | base64 -d > {{ pull_secret_file }} |
29 | | - changed_when: true |
| 42 | + register: _pull_secret_rhoso |
| 43 | + ignore_errors: true |
| 44 | + no_log: true |
| 45 | + when: _rhoso_kubeconfig_stat.stat.exists |
| 46 | + |
| 47 | + - name: Extract pull secret using default kubeconfig (fallback) |
| 48 | + ansible.builtin.shell: >- |
| 49 | + set -o pipefail && |
| 50 | + oc get secret pull-secret -n openshift-config |
| 51 | + -o jsonpath='{.data.\.dockerconfigjson}' |
| 52 | + | base64 -d > {{ pull_secret_file }} |
| 53 | + register: _pull_secret_default |
| 54 | + ignore_errors: true |
30 | 55 | no_log: true |
| 56 | + when: _rhoso_kubeconfig_stat.stat.exists == false or _pull_secret_rhoso is failed |
| 57 | + |
| 58 | + - name: Verify pull secret file was created and is valid JSON |
| 59 | + ansible.builtin.shell: python3 -c "import json; d=json.load(open('{{ pull_secret_file }}')); print(len(d.get('auths',{})), 'registries found')" |
| 60 | + register: _pull_secret_verify |
| 61 | + ignore_errors: true |
| 62 | + |
| 63 | + - name: Fail with diagnostic info if pull secret extraction failed |
| 64 | + ansible.builtin.fail: |
| 65 | + msg: | |
| 66 | + Failed to extract pull secret from host cluster. |
| 67 | + rhoso_kubeconfig exists: {{ _rhoso_kubeconfig_stat.stat.exists }} |
| 68 | + rhoso_kubeconfig result: {{ 'skipped' if _pull_secret_rhoso is skipped else ('ok' if _pull_secret_rhoso is success else 'FAILED rc=' + (_pull_secret_rhoso.rc | default('?') | string)) }} |
| 69 | + default kubeconfig result: {{ 'skipped' if _pull_secret_default is skipped else ('ok' if _pull_secret_default is success else 'FAILED rc=' + (_pull_secret_default.rc | default('?') | string)) }} |
| 70 | + pull secret validation: {{ _pull_secret_verify.stdout | default('FAILED - ' + _pull_secret_verify.stderr | default('unknown error')) }} |
| 71 | + when: _pull_secret_verify is failed |
31 | 72 |
|
32 | 73 | - name: Create the installer directory |
33 | 74 | ansible.builtin.file: |
|
0 commit comments