Skip to content

Commit a8bfaf2

Browse files
committed
2 small fixes
1 parent 64f70a1 commit a8bfaf2

1 file changed

Lines changed: 65 additions & 42 deletions

File tree

roles/api/tasks/hasura-install.yml

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@
5252
when:
5353
- installation_mode == "upgrade"
5454
- hasura_admin_secret_file.stat.exists
55-
- api_use_existing_hasura_on_upgrade | default(false) | bool
5655

57-
- name: set hasura admin secret from existing file
56+
- name: cache existing hasura admin secret during upgrade
5857
set_fact:
59-
api_hasura_admin_secret: "{{ existing_hasura_admin_secret['content'] | b64decode | trim }}"
58+
api_existing_hasura_admin_secret: "{{ existing_hasura_admin_secret['content'] | b64decode | trim }}"
6059
when:
6160
- installation_mode == "upgrade"
6261
- hasura_admin_secret_file.stat.exists
62+
63+
- name: set hasura admin secret from existing file
64+
set_fact:
65+
api_hasura_admin_secret: "{{ api_existing_hasura_admin_secret }}"
66+
when:
67+
- installation_mode == "upgrade"
6368
- api_use_existing_hasura_on_upgrade | default(false) | bool
69+
- api_existing_hasura_admin_secret is defined
6470

6571
- name: set static hasura admin pwd for test purposes only
6672
set_fact:
@@ -76,17 +82,6 @@
7682
when:
7783
- api_hasura_admin_secret is not defined
7884

79-
- name: write hasura admin password to secrets directory
80-
copy:
81-
content: "{{ api_hasura_admin_secret }}\n"
82-
dest: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
83-
mode: "0600"
84-
owner: "{{ fworch_user }}"
85-
group: "{{ fworch_group }}"
86-
become: true
87-
when:
88-
- installation_mode != "upgrade" or not (api_use_existing_hasura_on_upgrade | default(false) | bool) or not hasura_admin_secret_file.stat.exists
89-
9085
- name: check for existing hasura cli file
9186
stat:
9287
path: "{{ api_hasura_cli_bin }}"
@@ -98,8 +93,19 @@
9893
{{
9994
installation_mode == "upgrade"
10095
and (api_existing_service_name | default('') | length > 0)
96+
and hasura_admin_secret_file.stat.exists
10197
}}
10298
99+
- name: fail when Hasura upgrade reuse was requested without reusable state
100+
fail:
101+
msg: >-
102+
Hasura upgrade fallback requires both an installed Hasura service unit and the existing
103+
{{ fworch_secrets_dir }}/hasura_admin_pwd secret file.
104+
when:
105+
- installation_mode == "upgrade"
106+
- api_use_existing_hasura_on_upgrade | default(false) | bool
107+
- not api_hasura_upgrade_reuse_possible | bool
108+
103109
- name: build GitHub auth header
104110
set_fact:
105111
api_github_auth_header: "{{ {'Authorization': 'Bearer ' ~ api_github_token} if api_github_token is defined else {} }}"
@@ -177,6 +183,8 @@
177183
- name: fall back to existing Hasura after CLI download failure during upgrade
178184
set_fact:
179185
api_use_existing_hasura_on_upgrade: true
186+
api_service_name: "{{ api_existing_service_name }}"
187+
api_hasura_admin_secret: "{{ api_existing_hasura_admin_secret }}"
180188
when: api_hasura_upgrade_reuse_possible | bool
181189

182190
- name: show Hasura CLI upgrade fallback decision
@@ -217,6 +225,8 @@
217225
- name: fall back to existing Hasura after direct CLI download failure during upgrade
218226
set_fact:
219227
api_use_existing_hasura_on_upgrade: true
228+
api_service_name: "{{ api_existing_service_name }}"
229+
api_hasura_admin_secret: "{{ api_existing_hasura_admin_secret }}"
220230
when: api_hasura_upgrade_reuse_possible | bool
221231

222232
- name: show Hasura direct CLI upgrade fallback decision
@@ -249,34 +259,6 @@
249259
- not api_cli_check.stat.exists
250260
- not api_use_existing_hasura_on_upgrade | default(false) | bool
251261

252-
- name: set hasura env variable
253-
set_fact:
254-
hasura_env:
255-
HASURA_GRAPHQL_DATABASE_URL: "postgres://{{ api_user }}:{{ api_user_password }}@{{ fworch_db_host }}:{{ fworch_db_port }}/{{ fworch_db_name }}"
256-
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
257-
HASURA_GRAPHQL_ENABLE_TELEMETRY: "false"
258-
HASURA_GRAPHQL_ADMIN_SECRET: "{{ api_hasura_admin_secret }}"
259-
HASURA_GRAPHQL_SERVER_HOST: "127.0.0.1"
260-
HASURA_GRAPHQL_SERVER_PORT: "8080"
261-
HASURA_GRAPHQL_LOG_LEVEL: "{{ api_log_level }}"
262-
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "{{ api_HASURA_GRAPHQL_ENABLED_LOG_TYPES }}"
263-
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: "/srv/console-assets"
264-
HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE: "true"
265-
HASURA_GRAPHQL_CORS_DOMAIN: "*"
266-
HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS: "{{ api_HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS }}"
267-
HASURA_GRAPHQL_JWT_SECRET: "{{ {'type': api_hasura_jwt_alg, 'key': api_hasura_jwt_secret | regex_replace('\n', '\\n'), 'claims_namespace_path': '$'} | to_json }}"
268-
HTTP_PROXY: "{{ http_proxy }}"
269-
HTTPS_PROXY: "{{ https_proxy }}"
270-
http_proxy: "{{ http_proxy }}"
271-
https_proxy: "{{ https_proxy }}"
272-
no_proxy: "{{ no_proxy }}"
273-
NO_PROXY: "{{ no_proxy }}"
274-
275-
- name: show hasura env for debugging
276-
debug:
277-
var: hasura_env
278-
when: debug_level > '1'
279-
280262
- name: set Hasura image reuse mode
281263
set_fact:
282264
api_reuse_existing_hasura_image: >-
@@ -307,6 +289,8 @@
307289
set_fact:
308290
api_use_existing_hasura_on_upgrade: true
309291
api_reuse_existing_hasura_image: true
292+
api_service_name: "{{ api_existing_service_name }}"
293+
api_hasura_admin_secret: "{{ api_existing_hasura_admin_secret }}"
310294
when: api_hasura_upgrade_reuse_possible | bool
311295

312296
- name: show Hasura image upgrade fallback decision
@@ -327,6 +311,45 @@
327311
- not api_reuse_existing_hasura_image | bool
328312
- api_rollback_is_running | default(false) | bool == false
329313

314+
- name: write hasura admin password to secrets directory
315+
copy:
316+
content: "{{ api_hasura_admin_secret }}\n"
317+
dest: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
318+
mode: "0600"
319+
owner: "{{ fworch_user }}"
320+
group: "{{ fworch_group }}"
321+
become: true
322+
when:
323+
- installation_mode != "upgrade" or not (api_use_existing_hasura_on_upgrade | default(false) | bool) or not hasura_admin_secret_file.stat.exists
324+
325+
- name: set hasura env variable
326+
set_fact:
327+
hasura_env:
328+
HASURA_GRAPHQL_DATABASE_URL: "postgres://{{ api_user }}:{{ api_user_password }}@{{ fworch_db_host }}:{{ fworch_db_port }}/{{ fworch_db_name }}"
329+
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
330+
HASURA_GRAPHQL_ENABLE_TELEMETRY: "false"
331+
HASURA_GRAPHQL_ADMIN_SECRET: "{{ api_hasura_admin_secret }}"
332+
HASURA_GRAPHQL_SERVER_HOST: "127.0.0.1"
333+
HASURA_GRAPHQL_SERVER_PORT: "8080"
334+
HASURA_GRAPHQL_LOG_LEVEL: "{{ api_log_level }}"
335+
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "{{ api_HASURA_GRAPHQL_ENABLED_LOG_TYPES }}"
336+
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: "/srv/console-assets"
337+
HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE: "true"
338+
HASURA_GRAPHQL_CORS_DOMAIN: "*"
339+
HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS: "{{ api_HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS }}"
340+
HASURA_GRAPHQL_JWT_SECRET: "{{ {'type': api_hasura_jwt_alg, 'key': api_hasura_jwt_secret | regex_replace('\n', '\\n'), 'claims_namespace_path': '$'} | to_json }}"
341+
HTTP_PROXY: "{{ http_proxy }}"
342+
HTTPS_PROXY: "{{ https_proxy }}"
343+
http_proxy: "{{ http_proxy }}"
344+
https_proxy: "{{ https_proxy }}"
345+
no_proxy: "{{ no_proxy }}"
346+
NO_PROXY: "{{ no_proxy }}"
347+
348+
- name: show hasura env for debugging
349+
debug:
350+
var: hasura_env
351+
when: debug_level > '1'
352+
330353
- name: write Hasura env file for Podman
331354
copy:
332355
dest: "{{ api_env_file }}"

0 commit comments

Comments
 (0)