1
0
Fork 0

Add a role for Wiki.js

This commit is contained in:
Daniele Tricoli 2020-09-12 17:50:34 +02:00
parent d54c6b1fc4
commit 914204fb70
5 changed files with 272 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
wikijs_version: 2.5.132
wikijs_tarball: wiki-js.tar.gz
wikijs_download_url: "https://github.com/Requarks/wiki/releases/download/{{ wikijs_version }}/{{ wikijs_tarball }}"
wikijs_tarball_sha256: 80ae1f6d82adee7a90d17a689a6a9c9092b2ba46419f642d8eefb0471b46c24a
wikijs_dir: /srv/wikijs
wikijs_port: 3000
wikijs_db_type: postgres
wikijs_db_host: localhost
wikijs_db_port: 5432
wikijs_db_user: wikijs
wikijs_db_pass: wikijsrocks
wikijs_db_db: wiki
wikijs_db_ssl: false
# SQLite only:
wikijs_db_storage: database.sqlite
wikijs_bind_ip: 0.0.0.0
wikijs_log_level: info

101
roles/wikijs/tasks/main.yml Normal file
View File

@ -0,0 +1,101 @@
---
- name: install nodejs
apt:
name:
- nodejs
# See note on step "fetch native bindings for SQLite3".
# - npm
update_cache: true
cache_valid_time: 3600
- name: ensure wikijs group exits
group:
name: wikijs
- name: ensure wikijs user exists and has restrictive settings
user:
name: wikijs
groups: wikijs
password: "*"
shell: /usr/sbin/nologin
- name: check if the directory where we deploy Wiki.js exists
stat:
path: "{{ wikijs_dir }}"
register: deploy_directory
- name: backup sqlite database to /tmp
command:
cmd: mv "{{ wikijs_dir }}/{{ wikijs_db_storage }}" /tmp
creates: "/tmp/{{ wikijs_db_storage }}"
removes: "{{ wikijs_dir }}/{{ wikijs_db_storage }}"
when: deploy_directory.stat.exists and wikijs_db_type == "sqlite"
- name: remove previous installation of Wiki.js if exists
file:
path: "{{ wikijs_dir }}"
state: absent
when: deploy_directory.stat.exists
- name: ensure that the directory where we deploy Wiki.js exists
file:
path: "{{ wikijs_dir }}"
state: directory
owner: wikijs
group: wikijs
mode: "0750"
- name: download Wiki.js in /tmp
get_url:
url: "{{ wikijs_download_url }}"
dest: /tmp
checksum: "sha256:{{ wikijs_tarball_sha256 }}"
- name: unarchive Wiki.js
unarchive:
src: "/tmp/{{ wikijs_tarball }}"
dest: "{{ wikijs_dir }}"
remote_src: true
- name: install config.yml
template:
src: config.yml.j2
dest: "{{ wikijs_dir }}/config.yml"
# This step is in the install guide but it's discouraged by upstream in another
# part of the guide. It also take too much time end it's not worth it since
# sqlite is used only for testing or deploy where performance are not so
# critical (i.e single user deploy).
# - name: fetch native bindings for SQLite3
# command:
# cmd: npm rebuild sqlite3
# chdir: "{{ wikijs_dir }}"
# when: wikijs_db_type == "sqlite"
- name: check if a sqlite database backup exists
stat:
path: "/tmp/{{ wikijs_db_storage }}"
when: wikijs_db_type == "sqlite"
register: sqlite_database_backup
- name: restore the backup of sqlite database
command:
cmd: mv "/tmp/{{ wikijs_db_storage }}" "{{ wikijs_dir }}"
creates: "{{ wikijs_dir }}/{{ wikijs_db_storage }}"
removes: "/tmp/{{ wikijs_db_storage }}"
when: sqlite_database_backup.stat.exists and wikijs_db_type == "sqlite"
- name: install wikijs systemd unit file
template:
src: etc/systemd/system/wikijs.service.j2
dest: /etc/systemd/system/wikijs.service
- name: enable wikijs.service
systemd:
name: wikijs
enabled: true
- name: ensure Wiki.js is running
systemd:
name: wikijs
state: started

View File

@ -0,0 +1,131 @@
# Ansible managed.
#######################################################################
# Wiki.js - CONFIGURATION #
#######################################################################
# Full documentation + examples:
# https://docs.requarks.io/install
# ---------------------------------------------------------------------
# Port the server should listen to
# ---------------------------------------------------------------------
port: {{ wikijs_port }}
# ---------------------------------------------------------------------
# Database
# ---------------------------------------------------------------------
# Supported Database Engines:
# - postgres = PostgreSQL 9.5 or later
# - mysql = MySQL 8.0 or later (5.7.8 partially supported, refer to docs)
# - mariadb = MariaDB 10.2.7 or later
# - mssql = MS SQL Server 2012 or later
# - sqlite = SQLite 3.9 or later
db:
type: {{ wikijs_db_type }}
# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: {{ wikijs_db_host }}
port: {{ wikijs_db_port }}
user: {{ wikijs_db_user }}
pass: {{ wikijs_db_pass }}
db: {{ wikijs_db_db }}
ssl: {{ wikijs_db_ssl }}
# Optional - PostgreSQL / MySQL / MariaDB only:
# -> Uncomment lines you need below and set `auto` to false
# -> Full list of accepted options: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
sslOptions:
auto: true
# rejectUnauthorized: false
# ca: path/to/ca.crt
# cert: path/to/cert.crt
# key: path/to/key.pem
# pfx: path/to/cert.pfx
# passphrase: xyz123
# SQLite only:
storage: {{ wikijs_db_storage }}
#######################################################################
# ADVANCED OPTIONS #
#######################################################################
# Do not change unless you know what you are doing!
# ---------------------------------------------------------------------
# SSL/TLS Settings
# ---------------------------------------------------------------------
# Consider using a reverse proxy (e.g. nginx) if you require more
# advanced options than those provided below.
ssl:
enabled: false
port: 3443
# Provider to use, possible values: custom, letsencrypt
provider: custom
# ++++++ For custom only ++++++
# Certificate format, either 'pem' or 'pfx':
format: pem
# Using PEM format:
key: path/to/key.pem
cert: path/to/cert.pem
# Using PFX format:
pfx: path/to/cert.pfx
# Passphrase when using encrypted PEM / PFX keys (default: null):
passphrase: null
# Diffie Hellman parameters, with key length being greater or equal
# to 1024 bits (default: null):
dhparam: null
# ++++++ For letsencrypt only ++++++
domain: wiki.yourdomain.com
subscriberEmail: admin@example.com
# ---------------------------------------------------------------------
# Database Pool Options
# ---------------------------------------------------------------------
# Refer to https://github.com/vincit/tarn.js for all possible options
pool:
# min: 2
# max: 10
# ---------------------------------------------------------------------
# IP address the server should listen to
# ---------------------------------------------------------------------
# Leave 0.0.0.0 for all interfaces
bindIP: {{ wikijs_bind_ip }}
# ---------------------------------------------------------------------
# Log Level
# ---------------------------------------------------------------------
# Possible values: error, warn, info (default), verbose, debug, silly
logLevel: {{ wikijs_log_level }}
# ---------------------------------------------------------------------
# Offline Mode
# ---------------------------------------------------------------------
# If your server cannot access the internet. Set to true and manually
# download the offline files for sideloading.
offline: false
# ---------------------------------------------------------------------
# High-Availability
# ---------------------------------------------------------------------
# Set to true if you have multiple concurrent instances running off the
# same DB (e.g. Kubernetes pods / load balanced instances). Leave false
# otherwise. You MUST be using PostgreSQL to use this feature.
ha: false
# ---------------------------------------------------------------------
# Data Path
# ---------------------------------------------------------------------
# Writeable data path used for cache and temporary user uploads.
dataPath: ./data

View File

@ -0,0 +1,15 @@
# Ansible managed.
[Unit]
Description=Wiki.js
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always
User=wikijs
Environment=NODE_ENV=production
WorkingDirectory={{ wikijs_dir }}
[Install]
WantedBy=multi-user.target

View File

@ -18,3 +18,6 @@
- {role: ../roles/snake_oil_dehydrated}
- {role: ../roles/mailserver}
- {role: ../roles/weechat}
# Uncomment to test wikijs role: it's commented since the tarball that we
# have to download is more than 60MB.
# - {role: ../roles/wikijs, become: true, wikijs_db_type: sqlite}