From c06715efb9b04f44ec0b355f33052ebc2f5a4d4b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 23 Sep 2024 22:47:49 +0100 Subject: [PATCH 1/4] 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/4] 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: From 18afcdb8dd86fced1d56d255a6c49a6fa0551112 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Tue, 24 Sep 2024 09:49:37 +0100 Subject: [PATCH 3/4] Use stat helper to detect the database file This is cleaner than using a custom shell script. --- roles/code-submitter/tasks/main.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/roles/code-submitter/tasks/main.yml b/roles/code-submitter/tasks/main.yml index 3f0542c..d930ab3 100644 --- a/roles/code-submitter/tasks/main.yml +++ b/roles/code-submitter/tasks/main.yml @@ -77,9 +77,9 @@ 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") + stat: + path: "{{ install_dir }}/sqlite.db" + register: database_file - 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` @@ -91,7 +91,10 @@ environment: PYTHONPATH: "{{ install_dir }}" become_user: www-data - when: code_submitter_repo.changed or detect_database.changed # noqa: no-handler - Use a handler to ensure execution order + when: | # noqa: no-handler - Use a handler to ensure execution order + code_submitter_repo.changed or + database_file.stat.isreg is not defined or + not database_file.stat.isreg - name: Enable service service: From be8f01eb97bbeb6d1cc5de437f811ed8ff77032b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Tue, 24 Sep 2024 22:47:09 +0100 Subject: [PATCH 4/4] Drop redundant noqa --- roles/code-submitter/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/code-submitter/tasks/main.yml b/roles/code-submitter/tasks/main.yml index d930ab3..ae0070e 100644 --- a/roles/code-submitter/tasks/main.yml +++ b/roles/code-submitter/tasks/main.yml @@ -91,7 +91,7 @@ environment: PYTHONPATH: "{{ install_dir }}" become_user: www-data - when: | # noqa: no-handler - Use a handler to ensure execution order + when: | code_submitter_repo.changed or database_file.stat.isreg is not defined or not database_file.stat.isreg