From c06715efb9b04f44ec0b355f33052ebc2f5a4d4b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 23 Sep 2024 22:47:49 +0100 Subject: [PATCH 1/2] Replace literal with equivalent variable This avoids potential desync between this logic and the corrsponding location of the files. --- roles/code-submitter/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/code-submitter/tasks/main.yml b/roles/code-submitter/tasks/main.yml index 0c8f7ef..9b6c8fb 100644 --- a/roles/code-submitter/tasks/main.yml +++ b/roles/code-submitter/tasks/main.yml @@ -82,9 +82,9 @@ - "{{ venv_dir }}/bin/alembic" - upgrade - head - chdir: /srv/code-submitter + chdir: "{{ install_dir }}" environment: - PYTHONPATH: /srv/code-submitter + PYTHONPATH: "{{ install_dir }}" become_user: www-data when: code_submitter_repo.changed # noqa: no-handler - Use a handler to ensure execution order From 2680c4fcebe9d31c9578f277f339ffbd3bbfcbcc Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 23 Sep 2024 22:49:34 +0100 Subject: [PATCH 2/2] Create the code-submitter database if missing This ensures that the database can be re-created if it's been removed (as we do between SR years), even if the code hasn't changed. Fixes https://github.com/srobo/ansible/issues/58. --- roles/code-submitter/tasks/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/roles/code-submitter/tasks/main.yml b/roles/code-submitter/tasks/main.yml index 9b6c8fb..3f0542c 100644 --- a/roles/code-submitter/tasks/main.yml +++ b/roles/code-submitter/tasks/main.yml @@ -76,6 +76,11 @@ notify: Reload nginx +- name: Check if database exists + shell: test -f "{{ install_dir }}/sqlite.db" || echo "Missing" + register: detect_database + changed_when: detect_database.stdout.startswith("Missing") + - name: Install database # noqa: no-changed-when - We want to always run this (it handles its own idempotency) shell: # noqa: command-instead-of-shell - We need this to use `environment` argv: @@ -86,7 +91,7 @@ environment: PYTHONPATH: "{{ install_dir }}" become_user: www-data - when: code_submitter_repo.changed # noqa: no-handler - Use a handler to ensure execution order + when: code_submitter_repo.changed or detect_database.changed # noqa: no-handler - Use a handler to ensure execution order - name: Enable service service: