writefreely/tasks/main.yaml
changeset 17 41034ea52480
parent 2 2556522a2a45
child 18 ea20908c3904
--- a/writefreely/tasks/main.yaml	Sat May 02 18:38:02 2020 -0500
+++ b/writefreely/tasks/main.yaml	Sun May 03 12:57:47 2020 -0500
@@ -1,8 +1,106 @@
 ---
 
-- name: install apt packages
-  apt: name="{{writefreely_apt_packages}}"
+- name: add writefreely user
+  become: yes
+  user: name="{{writefreely_user}}"
+
+- name: unarchive writefreely
+  become: yes
+  unarchive:
+    remote_src: yes
+    src: "{{writefreely_tar}}"
+    dest: "/tmp/"
+    creates: "/tmp/writefreely/"
+    owner: "root"
+    group: "root"
+
+- name: install writefreely binary
+  become: yes
+  command: "install -m 0755 -o {{writefreely_user}} -g {{writefreely_user}} -t /usr/local/bin /tmp/writefreely/writefreely"
+  changed_when: false
+
+- name: create root dir
+  become: yes
+  file:
+    path: "{{writefreely_dir}}"
+    state: "directory"
+    owner: "{{writefreely_user}}"
+    group: "{{writefreely_user}}"
+    mode: "0755"
+  notify: reload service
+
+- name: create instance dir
+  become: yes
+  file:
+    path: "{{writefreely_dir}}/{{writefreely_instance}}"
+    state: "directory"
+    owner: "{{writefreely_user}}"
+    group: "{{writefreely_user}}"
+    mode: "0755"
+  notify: reload service
+
+- name: install static content
+  become: yes
+  copy:
+    src: "/tmp/writefreely/"
+    remote_src: yes
+    dest: "{{writefreely_dir}}/{{writefreely_instance}}/"
+    owner: "{{writefreely_user}}"
+    group: "{{writefreely_user}}"
+    mode: "0755"
 
-- name: download writefreely
-  archive:
-    src: "{{writefreely_release}}"
+- name: configure
+  become: yes
+  template:
+    src: "config.ini.j2"
+    dest: "{{writefreely_dir}}/{{writefreely_instance}}/config.ini"
+    mode: "0644"
+    owner: "{{writefreely_user}}"
+    group: "{{writefreely_user}}"
+  notify: reload service
+
+- name: generate keys
+  become: yes
+  become_user: "{{writefreely_user}}"
+  command: "writefreely keys gen"
+  args:
+    chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
+
+- name: check if db exists
+  stat:
+    path: "{{writefreely_dir}}/{{writefreely_instance}}/writefreely.db"
+  register: db_file
+
+- name: create db
+  become: yes
+  become_user: "{{writefreely_user}}"
+  command: "writefreely db init"
+  args:
+    chdir: "{{writefreely_dir}}/{{writefreely_instance}}/"
+  when: not db_file.stat.exists
+
+- name: create admin
+  become: yes
+  become_user: "{{writefreely_user}}"
+  command: "writefreely --create-admin admin:admin"
+  args:
+    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:
+    src: "[email protected]"
+    dest: "/lib/systemd/system/[email protected]"
+
+- name: ensure service is started
+  become: yes
+  systemd: name="[email protected]{{writefreely_instance}}.service" enabled="yes" state="started"