|
18 | 18 | # We would wait till forbidden error is received. It indicates the endpoint |
19 | 19 | # is reachable. |
20 | 20 |
|
| 21 | +- name: Get API server URL from current context |
| 22 | + ansible.builtin.include_tasks: _get_api_server.yml |
| 23 | + |
21 | 24 | - name: Wait until the OCP API endpoint is reachable. |
22 | 25 | ansible.builtin.uri: |
23 | | - url: "{{ cifmw_openshift_api }}" |
| 26 | + url: "{{ _current_api_server }}" |
24 | 27 | return_content: true |
25 | 28 | validate_certs: false |
26 | 29 | status_code: 403 |
27 | 30 | register: ocp_api_result |
28 | 31 | until: ocp_api_result.status == 403 |
29 | 32 | retries: "{{ cifmw_openshift_adm_retry_count }}" |
30 | | - delay: 5 |
| 33 | + delay: 30 |
31 | 34 |
|
32 | 35 | - name: Get nodes list |
33 | 36 | ansible.builtin.import_tasks: _get_nodes.yml |
|
39 | 42 | name: "{{ item }}" |
40 | 43 | state: uncordon |
41 | 44 | kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 45 | + context: "{{ cifmw_openshift_adm_context }}" |
42 | 46 | validate_certs: false |
43 | 47 | loop: "{{ _nodes.resources | map(attribute='metadata.name') | list }}" |
44 | 48 | register: _node_status |
45 | 49 | until: _node_status.result is defined |
46 | 50 | retries: "{{ cifmw_openshift_adm_retry_count }}" |
47 | | - delay: 5 |
| 51 | + delay: 30 |
48 | 52 |
|
49 | 53 | - name: Check for pending certificate approval. |
50 | 54 | when: |
51 | 55 | - _openshift_adm_check_cert_approve | default(false) | bool |
52 | | - register: _approve_csr |
53 | | - approve_csr: |
54 | | - k8s_config: "{{ cifmw_openshift_kubeconfig }}" |
55 | | - retries: 30 |
56 | | - delay: 10 |
57 | | - until: |
58 | | - - _approve_csr is defined |
59 | | - - _approve_csr.rc is defined |
60 | | - - _approve_csr.rc == 0 |
| 56 | + block: |
| 57 | + - name: Set current context to admin for CSR approval |
| 58 | + ansible.builtin.shell: | |
| 59 | + KUBECONFIG="{{ cifmw_openshift_kubeconfig }}" oc config use-context "{{ cifmw_openshift_adm_context }}" |
| 60 | +
|
| 61 | + - name: Approve pending certificate requests |
| 62 | + register: _approve_csr |
| 63 | + approve_csr: |
| 64 | + k8s_config: "{{ cifmw_openshift_kubeconfig }}" |
| 65 | + retries: 10 |
| 66 | + delay: 30 |
| 67 | + until: |
| 68 | + - _approve_csr is defined |
| 69 | + - _approve_csr.rc is defined |
| 70 | + - _approve_csr.rc == 0 |
61 | 71 |
|
62 | 72 | - name: Wait until the OpenShift cluster is stable. |
63 | 73 | environment: |
|
68 | 78 | oc adm wait-for-stable-cluster --minimum-stable-period=5s --timeout=30m |
69 | 79 |
|
70 | 80 | - name: Wait until OCP login succeeds. |
71 | | - community.okd.openshift_auth: |
72 | | - host: "{{ cifmw_openshift_api }}" |
73 | | - password: "{{ cifmw_openshift_password }}" |
74 | | - state: present |
75 | | - username: "{{ cifmw_openshift_user }}" |
76 | | - validate_certs: false |
77 | | - register: _oc_login_result |
78 | | - until: _oc_login_result.k8s_auth is defined |
79 | | - retries: "{{ cifmw_openshift_adm_retry_count }}" |
80 | | - delay: 2 |
| 81 | + block: |
| 82 | + - name: Ensure admin context is set for login |
| 83 | + ansible.builtin.shell: | |
| 84 | + KUBECONFIG="{{ cifmw_openshift_kubeconfig }}" oc config use-context "{{ cifmw_openshift_adm_context }}" |
| 85 | +
|
| 86 | + # Re-get API server URL since admin context may point to a different |
| 87 | + # cluster than the initial context used for reachability check above |
| 88 | + - name: Get API server URL from admin context |
| 89 | + ansible.builtin.include_tasks: _get_api_server.yml |
| 90 | + |
| 91 | + - name: Authenticate to OpenShift cluster |
| 92 | + community.okd.openshift_auth: |
| 93 | + host: "{{ _current_api_server }}" |
| 94 | + password: "{{ cifmw_openshift_password }}" |
| 95 | + state: present |
| 96 | + username: "{{ cifmw_openshift_user }}" |
| 97 | + validate_certs: false |
| 98 | + register: _oc_login_result |
| 99 | + until: _oc_login_result.k8s_auth is defined |
| 100 | + retries: "{{ cifmw_openshift_adm_retry_count }}" |
| 101 | + delay: 30 |
0 commit comments