writefreely/tasks/main.yaml
author Luke Hoersten <luke@hoersten.org>
Sat, 03 Jul 2021 11:16:17 -0500
changeset 155 4d45841961e7
parent 51 19fa7aa47bf1
permissions -rw-r--r--
Added ops template to main.

---

- 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
  copy:
    src: "/tmp/writefreely/writefreely"
    dest: "/usr/local/bin/"
    remote_src: yes
    owner: "{{writefreely_user}}"
    group: "{{writefreely_user}}"
    mode: "0755"
  notify: migrate db

- name: create instance dir
  become: yes
  file:
    path: "{{item}}"
    state: "directory"
    owner: "{{writefreely_user}}"
    group: "{{writefreely_user}}"
    mode: "0755"
  notify: reload service
  loop:
    - "{{writefreely_dir}}"
    - "{{writefreely_dir}}/{{writefreely_instance}}"

- 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: 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: 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 keys_file.stat.exists

- 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: install systemd service
  become: yes
  template:
    src: "[email protected]"
    dest: "/lib/systemd/system/[email protected]"

- name: ensure service is started
  become: yes
  systemd: name="writefreely@{{writefreely_instance}}.service" enabled="yes" state="started"