Fix writefreely role to be idempotent.
authorLuke Hoersten <luke@hoersten.org>
Sat, 16 May 2020 10:07:24 -0500
changeset 26 b0e4ad2f4291
parent 25 b4e52ddd1210
child 27 8fddefdd948b
Fix writefreely role to be idempotent.
writefreely/handlers/main.yaml
writefreely/tasks/main.yaml
--- a/writefreely/handlers/main.yaml	Sat May 16 09:55:46 2020 -0500
+++ b/writefreely/handlers/main.yaml	Sat May 16 10:07:24 2020 -0500
@@ -3,3 +3,10 @@
 - name: reload service
   become: yes
   systemd: name="writefreely@{{writefreely_instance}}.service" enabled="yes" daemon_reload="yes"
+
+- name: migrate db
+  become: yes
+  become_user: "{{writefreely_user}}"
+  command: "writefreely db migrate"
+  args:
+    chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
--- a/writefreely/tasks/main.yaml	Sat May 16 09:55:46 2020 -0500
+++ b/writefreely/tasks/main.yaml	Sat May 16 10:07:24 2020 -0500
@@ -23,6 +23,7 @@
     owner: "{{writefreely_user}}"
     group: "{{writefreely_user}}"
     mode: "0755"
+  notify: migrate db
 
 - name: create root dir
   become: yes
@@ -64,12 +65,18 @@
     group: "{{writefreely_user}}"
   notify: reload service
 
+- name: check if keys exists
+  stat:
+    path: "{{writefreely_dir}}/{{writefreely_instance}}/keys/cookies_auth.aes256"
+  register: keys_file
+
 - name: generate keys
   become: yes
   become_user: "{{writefreely_user}}"
   command: "writefreely keys gen"
   args:
     chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
+  when: not key_file.stat.exists
 
 - name: check if db exists
   stat:
@@ -92,14 +99,6 @@
     chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
   when: not db_file.stat.exists
 
-- name: migrate db
-  become: yes
-  become_user: "{{writefreely_user}}"
-  command: "writefreely db migrate"
-  args:
-    chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
-  when: db_file.stat.exists
-
 - name: install systemd service
   become: yes
   template: