|
9 | 9 | # This file sets the following variables: |
10 | 10 | # - quay_oauth_client_id |
11 | 11 | # - quay_oauth_client_secret |
12 | | -# - quay_oauth_token |
| 12 | +# - quay_oauth_token (only when a token is (re)generated) |
| 13 | + |
| 14 | +- name: Read existing OAuth credentials Secret |
| 15 | + no_log: true |
| 16 | + kubernetes.core.k8s_info: |
| 17 | + api_version: v1 |
| 18 | + kind: Secret |
| 19 | + name: quay-oauth-credentials |
| 20 | + namespace: quay-enterprise |
| 21 | + register: r_quay_oauth_secret_existing |
| 22 | + |
| 23 | +- name: Determine whether OAuth application is already provisioned |
| 24 | + ansible.builtin.set_fact: |
| 25 | + quay_oauth_secret_exists: "{{ r_quay_oauth_secret_existing.resources | default([]) | length > 0 }}" |
| 26 | + |
| 27 | +- name: Reuse credentials from existing Secret |
| 28 | + no_log: true |
| 29 | + when: quay_oauth_secret_exists |
| 30 | + ansible.builtin.set_fact: |
| 31 | + quay_oauth_client_id: "{{ r_quay_oauth_secret_existing.resources[0].data['client-id'] | b64decode }}" |
| 32 | + quay_oauth_client_secret: "{{ r_quay_oauth_secret_existing.resources[0].data['client-secret'] | b64decode }}" |
| 33 | + quay_oauth_current_scopes: "{{ r_quay_oauth_secret_existing.resources[0].data['scopes'] | default('') | b64decode }}" |
13 | 34 |
|
14 | 35 | - name: Create Quay organization for OAuth application |
15 | 36 | no_log: true |
|
33 | 54 | retries: 3 |
34 | 55 | delay: 5 |
35 | 56 | when: |
| 57 | + - not quay_oauth_secret_exists |
36 | 58 | - quay_initial_token is defined |
37 | 59 | - quay_initial_token | length > 0 |
38 | 60 | until: |
|
61 | 83 | retries: 5 |
62 | 84 | delay: 10 |
63 | 85 | when: |
| 86 | + - not quay_oauth_secret_exists |
64 | 87 | - quay_initial_token is defined |
65 | 88 | - quay_initial_token | length > 0 |
66 | 89 | until: |
|
81 | 104 | - r_quay_oauth_app.json.client_secret is defined |
82 | 105 |
|
83 | 106 | - name: Get current quay-app Deployment state before config update |
| 107 | + when: not quay_oauth_secret_exists |
84 | 108 | kubernetes.core.k8s_info: |
85 | 109 | api_version: apps/v1 |
86 | 110 | kind: Deployment |
|
108 | 132 | retries: "{{ k8s_retries }}" |
109 | 133 | delay: "{{ k8s_delay }}" |
110 | 134 | when: |
| 135 | + - not quay_oauth_secret_exists |
111 | 136 | - quay_oauth_client_id is defined |
112 | 137 | - quay_oauth_client_id | length > 0 |
113 | 138 | until: r_quay_config_secret_oauth is success |
|
160 | 185 | when: |
161 | 186 | - quay_oauth_client_id is defined |
162 | 187 | - quay_oauth_client_id | length > 0 |
| 188 | + - not quay_oauth_secret_exists or (quay_oauth_current_scopes.split() | sort) != (quayOAuthApp.scopes.split() | sort) |
163 | 189 | until: |
164 | 190 | - r_quay_oauth_token is defined |
165 | 191 | - r_quay_oauth_token.status in [302, 303] |
|
0 commit comments