From 18afcdb8dd86fced1d56d255a6c49a6fa0551112 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Tue, 24 Sep 2024 09:49:37 +0100 Subject: [PATCH 1/2] 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 2/2] 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