Fix writefreely role to be idempotent.
--- 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: