|
5 | 5 | - name: Assert control variables (aux user) |
6 | 6 | assert: |
7 | 7 | that: |
8 | | - - pg_aux_user_password|string|length > 0 |
9 | | - - pg_aux_database|string|length > 0 |
10 | | - when: pg_aux_user|string|length > 0 |
| 8 | + - pg_aux_user_password | string | length > 0 |
| 9 | + - pg_aux_database | string | length > 0 |
| 10 | + when: pg_aux_user | string | length > 0 |
11 | 11 |
|
12 | 12 | # Create namespace |
13 | 13 |
|
|
23 | 23 | vars: |
24 | 24 | pull_namespace: "{{ pg_namespace }}" |
25 | 25 | pull_secret: "{{ pg_dockerhub_pullsecret }}" |
26 | | - when: pg_dockerhub_pullsecret|string|length > 0 |
| 26 | + when: pg_dockerhub_pullsecret | string | length > 0 |
27 | 27 |
|
28 | 28 | - name: Creating namespace material |
29 | 29 | k8s: |
30 | | - definition: "{{ lookup('template', '{{ item }}.yaml.j2') }}" |
| 30 | + definition: "{{ lookup('template', item) }}" |
31 | 31 | wait: yes |
32 | 32 | loop: |
33 | | - - serviceaccount |
34 | | - - role-im-psp-unrestricted |
35 | | - - rolebinding-pg-sa |
| 33 | + - serviceaccount.yaml.j2 |
36 | 34 |
|
37 | 35 | # Secrets (database) ---------------------------------------------------------- |
38 | 36 |
|
|
52 | 50 | pg_aux_user_fact: "{{ pg_aux_user }}" |
53 | 51 | pg_aux_user_password_fact: "{{ pg_aux_user_password }}" |
54 | 52 | pg_aux_database_fact: "{{ pg_aux_database }}" |
55 | | - when: pg_s_result.resources|length == 0 |
| 53 | + when: pg_s_result.resources | length == 0 |
56 | 54 |
|
57 | 55 | - name: Set database secret facts (pre-deployed secrets) |
58 | 56 | set_fact: |
59 | | - pg_user_fact: "{{ pg_s_result.resources[0].data.database_admin_user|b64decode }}" |
60 | | - pg_user_password_fact: "{{ pg_s_result.resources[0].data.database_admin_user_password|b64decode }}" |
61 | | - pg_database_fact: "{{ pg_s_result.resources[0].data.database_name|b64decode }}" |
62 | | - pg_aux_user_fact: "{{ pg_s_result.resources[0].data.database_aux_user|b64decode }}" |
63 | | - pg_aux_user_password_fact: "{{ pg_s_result.resources[0].data.database_aux_user_password|b64decode }}" |
64 | | - pg_aux_database_fact: "{{ pg_s_result.resources[0].data.database_aux_database|b64decode }}" |
65 | | - when: pg_s_result.resources|length == 1 |
| 57 | + pg_user_fact: "{{ pg_s_result.resources[0].data.database_admin_user | b64decode }}" |
| 58 | + pg_user_password_fact: "{{ pg_s_result.resources[0].data.database_admin_user_password | b64decode }}" |
| 59 | + pg_database_fact: "{{ pg_s_result.resources[0].data.database_name | b64decode }}" |
| 60 | + pg_aux_user_fact: "{{ pg_s_result.resources[0].data.database_aux_user | b64decode }}" |
| 61 | + pg_aux_user_password_fact: "{{ pg_s_result.resources[0].data.database_aux_user_password | b64decode }}" |
| 62 | + pg_aux_database_fact: "{{ pg_s_result.resources[0].data.database_aux_database | b64decode }}" |
| 63 | + when: pg_s_result.resources | length == 1 |
66 | 64 |
|
67 | 65 | - name: Write Database secrets |
68 | 66 | k8s: |
69 | 67 | definition: "{{ lookup('template', 'secret.yaml.j2') }}" |
70 | 68 | wait: yes |
71 | | - when: pg_s_result.resources|length == 0 |
| 69 | + when: pg_s_result.resources | length == 0 |
72 | 70 |
|
73 | 71 | - name: Display Database admin password |
74 | 72 | debug: |
|
85 | 83 |
|
86 | 84 | - name: Assert {{ pg_vol_storageclass }} StorageClass |
87 | 85 | assert: |
88 | | - that: sc_result.resources|length == 1 |
| 86 | + that: sc_result.resources | length == 1 |
89 | 87 | fail_msg: The {{ pg_vol_storageclass }} StorageClass must be available on the cluster |
90 | 88 | when: pg_vol_storageclass != " " |
91 | 89 |
|
|
94 | 92 | definition: "{{ lookup('template', 'pvc-pg.yaml.j2') }}" |
95 | 93 | wait: yes |
96 | 94 | wait_timeout: "{{ wait_timeout }}" |
97 | | - when: pg_vol_size_g|int > 0 |
| 95 | + when: pg_vol_size_g | int > 0 |
98 | 96 |
|
99 | 97 | # Best practice ... wait for the PVC to bind. |
100 | 98 | # e.g. wait until resources[0].status.phase == Bound (initially Pending) |
|
106 | 104 | namespace: "{{ pg_namespace }}" |
107 | 105 | register: pg_pvc_result |
108 | 106 | until: >- |
109 | | - pg_pvc_result.resources|length > 0 |
| 107 | + pg_pvc_result.resources | length > 0 |
110 | 108 | and pg_pvc_result.resources[0].status is defined |
111 | 109 | and pg_pvc_result.resources[0].status.phase is defined |
112 | 110 | and pg_pvc_result.resources[0].status.phase == 'Bound' |
113 | 111 | delay: 5 |
114 | | - retries: "{{ (bind_timeout|int / 5)|int }}" |
| 112 | + retries: "{{ (bind_timeout | int / 5) | int }}" |
115 | 113 | when: |
116 | | - - pg_vol_size_g|int > 0 |
117 | | - - wait_for_bind|bool |
| 114 | + - pg_vol_size_g | int > 0 |
| 115 | + - wait_for_bind | bool |
118 | 116 |
|
119 | 117 | # Database volume (pg-copy) --------------------------------------------------- |
120 | 118 |
|
|
130 | 128 |
|
131 | 129 | - name: Assert {{ pg_copy_vol_storageclass }} StorageClass |
132 | 130 | assert: |
133 | | - that: sc_result.resources|length == 1 |
| 131 | + that: sc_result.resources | length == 1 |
134 | 132 | fail_msg: The {{ pg_copy_vol_storageclass }} StorageClass must be available on the cluster |
135 | 133 | when: pg_copy_vol_storageclass != " " |
136 | 134 |
|
|
150 | 148 | namespace: "{{ pg_namespace }}" |
151 | 149 | register: pg_copy_pvc_result |
152 | 150 | until: >- |
153 | | - pg_copy_pvc_result.resources|length > 0 |
| 151 | + pg_copy_pvc_result.resources | length > 0 |
154 | 152 | and pg_copy_pvc_result.resources[0].status is defined |
155 | 153 | and pg_copy_pvc_result.resources[0].status.phase is defined |
156 | 154 | and pg_copy_pvc_result.resources[0].status.phase == 'Bound' |
157 | 155 | delay: 5 |
158 | | - retries: "{{ (bind_timeout|int / 5)|int }}" |
159 | | - when: wait_for_bind|bool |
| 156 | + retries: "{{ (bind_timeout | int / 5) | int }}" |
| 157 | + when: wait_for_bind | bool |
160 | 158 |
|
161 | | - when: pg_copy_vol_size_g|int > 0 |
| 159 | + when: pg_copy_vol_size_g | int > 0 |
162 | 160 |
|
163 | 161 | # Database (postgres) --------------------------------------------------------- |
164 | 162 |
|
165 | 163 | - name: Postgres |
166 | 164 | k8s: |
167 | | - definition: "{{ lookup('template', '{{ item }}.yaml.j2') }}" |
| 165 | + definition: "{{ lookup('template', item) }}" |
168 | 166 | wait: yes |
169 | 167 | wait_timeout: "{{ wait_timeout }}" |
170 | 168 | loop: |
171 | | - - configmap-postgres-conf |
172 | | - - configmap-postgres-init |
173 | | - - service |
174 | | - - statefulset |
| 169 | + - configmap-postgres-conf.yaml.j2 |
| 170 | + - configmap-postgres-init.yaml.j2 |
| 171 | + - service.yaml.j2 |
| 172 | + - statefulset.yaml.j2 |
175 | 173 |
|
176 | 174 | - name: Wait for Postgres |
177 | 175 | k8s_info: |
|
181 | 179 | - app=postgres |
182 | 180 | register: result |
183 | 181 | until: >- |
184 | | - result.resources|length > 0 |
| 182 | + result.resources | length > 0 |
185 | 183 | and result.resources[0].status.containerStatuses is defined |
186 | | - and result.resources[0].status.containerStatuses|length == 1 |
| 184 | + and result.resources[0].status.containerStatuses | length == 1 |
187 | 185 | and result.resources[0].status.containerStatuses[0].ready is defined |
188 | 186 | and result.resources[0].status.containerStatuses[0].ready |
189 | 187 | delay: 20 |
190 | | - retries: "{{ (wait_timeout|int / 20)|int }}" |
| 188 | + retries: "{{ (wait_timeout | int / 20) | int }}" |
0 commit comments