Initialize repo for Wiki.js role.
This commit is contained in:
commit
0cb0bdf997
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Ansible Role: wikijs
|
||||||
|
|
||||||
|
This Ansible Role installs a rootless [wikijs](https://docs.requarks.io/guide/intro) container using Podman. It is intended to be composed with separate roles for Podman, database, and web proxy.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* [podman](docs/PODMAN.md)
|
||||||
|
* [containers.podman](https://github.com/containers/ansible-podman-collections)
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [postgresql](docs/POSTGRES.md) (optional)
|
||||||
|
* [nginx_conf](docs/examples/nginx_conf.yml) (optional)
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
See the role [defaults](defaults/main.yml) and the wikijs [environment variable](https://docs.requarks.io/install/docker) documentation. For a working example, see this [homelab stack](https://github.com/bleetube/satstack).
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: wikijs
|
||||||
|
roles:
|
||||||
|
- role: nginxinc.nginx_core.nginx
|
||||||
|
become: true
|
||||||
|
- role: anxs.postgresql
|
||||||
|
become: true
|
||||||
|
- role: alvistack.podman
|
||||||
|
become: true
|
||||||
|
- role: bleetube.wikijs
|
||||||
|
tags: wikijs
|
||||||
|
tasks:
|
||||||
|
- import_tasks: nginx_conf.yml
|
||||||
|
become: true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Systemd
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl --user status container-wikijs.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Upgrades
|
||||||
|
|
||||||
|
Configure `wikijs_version`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ansible-playbook playbooks/wikijs.yml --tags wikijs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backups
|
||||||
|
|
||||||
|
See the [postgres example](docs/examples/postgres-backup.sh).
|
29
defaults/main.yml
Normal file
29
defaults/main.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
wikijs_ports:
|
||||||
|
- "{{ wikijs_http_port|default(3000) }}:3000"
|
||||||
|
# - "{{ wikijs_https_port|default(3443) }}:3443"
|
||||||
|
|
||||||
|
wikijs_data_dir: /var/lib/wikijs
|
||||||
|
wikijs_volumes:
|
||||||
|
- "{{ wikijs_data_dir }}:/wiki/data/content"
|
||||||
|
#- ./wikijs/content:/wiki/data/content
|
||||||
|
#- /var/run/postgresql:/var/run/postgresql
|
||||||
|
|
||||||
|
# Vars for wikijs container
|
||||||
|
wikijs_image: ghcr.io/requarks/wiki
|
||||||
|
wikijs_name: wikijs
|
||||||
|
wikijs_version: 2
|
||||||
|
|
||||||
|
# https://docs.requarks.io/install/docker
|
||||||
|
wikijs_config:
|
||||||
|
DB_TYPE: sqlite
|
||||||
|
DB_FILEPATH: /wiki/data/database.sqlite
|
||||||
|
# DB_TYPE: postgres
|
||||||
|
# DB_HOST: host.containers.internal
|
||||||
|
# DB_PORT: 5432
|
||||||
|
# DB_NAME: wikijs
|
||||||
|
# DB_USER: wikijs
|
||||||
|
# DB_PASS: ''
|
||||||
|
# DB_SSL: false
|
||||||
|
# DB_SSL_CA:
|
||||||
|
# DB_PASS_FILE:
|
18
docs/PODMAN.md
Normal file
18
docs/PODMAN.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Podman
|
||||||
|
|
||||||
|
Example using [alvistack/ansible-role-podman](https://github.com/alvistack/ansible-role-podman):
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: podman
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- alvistack.podman
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: "Ensure loginctl enable-linger is set for {{ sysadmin_username }}"
|
||||||
|
command:
|
||||||
|
cmd: "loginctl enable-linger {{ sysadmin_username }}"
|
||||||
|
creates: "/var/lib/systemd/linger/{{ sysadmin_username }}"
|
||||||
|
```
|
38
docs/POSTGRES.md
Normal file
38
docs/POSTGRES.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# PostgreSQL
|
||||||
|
|
||||||
|
This variation of the [original role](https://github.com/Tronde/ansible_role_deploy_wikijs_with_mariadb_pod) is intended to be composed with another role that sets up the database. Here is an example using [anxs.postgresql](https://github.com/ANXS/postgresql)
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
roles:
|
||||||
|
- anxs.postgresql
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example Variables
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
postgresql_users:
|
||||||
|
- name: wikijs
|
||||||
|
pass: "{{ lookup('ansible.builtin.env', 'WIKIJS_POSTGRES_PASSWORD') }}"
|
||||||
|
encrypted: yes
|
||||||
|
state: present
|
||||||
|
|
||||||
|
postgresql_databases:
|
||||||
|
- name: wikijs
|
||||||
|
owner: wikijs
|
||||||
|
state: present
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, there are two users because both `localhost` and `%` (all-hosts wildcard) are [mutually exclusive](https://stackoverflow.com/q/10823854/9290). I am also using environment variables to separate secret stores from the repository.
|
||||||
|
|
||||||
|
## PG 15
|
||||||
|
|
||||||
|
I'm temporarily using this branch to get PG15:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# - src: https://github.com/ANXS/postgresql
|
||||||
|
- src: https://github.com/VladDm93/postgresql
|
||||||
|
version: postgres-14-15-support
|
||||||
|
name: anxs.postgresql
|
||||||
|
```
|
14
docs/examples/postgres-backup.sh
Executable file
14
docs/examples/postgres-backup.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
TARGET=example
|
||||||
|
TIMESTAMP=$(date +%m-%d-%Y)
|
||||||
|
|
||||||
|
# wikijs files
|
||||||
|
rsync --delete-after -ta ${TARGET}:/var/compose/wikijs $HOME/archive/${TARGET}/
|
||||||
|
|
||||||
|
# wikijs postgresql
|
||||||
|
BACKUP_DIR=$HOME/archive/${TARGET}/postgresql
|
||||||
|
DUMP_FILE=/var/lib/postgresql/wikijs_${TIMESTAMP}.dump.bz2
|
||||||
|
ssh root@${TARGET} "doas -u postgres /usr/bin/pg_dump -Fc wikijs | /usr/bin/bzip2 > ${DUMP_FILE}"
|
||||||
|
mkdir -p $HOME/archive/${TARGET}/postgresql/
|
||||||
|
rsync -tav ${TARGET}:${DUMP_FILE} $HOME/archive/${TARGET}/postgresql/
|
||||||
|
ssh root@${TARGET} rm -v ${DUMP_FILE}
|
23
tasks/main.yml
Normal file
23
tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
- name: Assert that we are not logged in as root
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_user_id != 'root'
|
||||||
|
fail_msg: "Podman containers are rootless, so please do not run this role as root."
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: wikijs_data_dir
|
||||||
|
- name: Assert that a data is configured.
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- wikijs_data_dir != ''
|
||||||
|
fail_msg: "Please set wikijs_data_dir to a valid directory."
|
||||||
|
|
||||||
|
- name: Ensure wikijs data dir exists.
|
||||||
|
file:
|
||||||
|
path: "{{ wikijs_data_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- import_tasks: podman.yml
|
||||||
|
- import_tasks: systemd.yml
|
32
tasks/podman.yml
Normal file
32
tasks/podman.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
#- name: Wiki.js | Build image
|
||||||
|
# register: podman_image_output
|
||||||
|
# containers.podman.podman_image:
|
||||||
|
# name: requarks/wiki
|
||||||
|
# path: ~/src/wiki
|
||||||
|
# tag: "wikijs-{{ wikijs_version }}"
|
||||||
|
# validate_certs: true
|
||||||
|
# pull: false
|
||||||
|
# state: build
|
||||||
|
# build:
|
||||||
|
# file: ~/src/wiki/dev/containers/Dockerfile
|
||||||
|
|
||||||
|
#- ansible.builtin.debug:
|
||||||
|
# var: podman_image_output
|
||||||
|
|
||||||
|
# https://github.com/requarks/wiki/blob/main/dev/build/Dockerfile
|
||||||
|
- name: Wiki.js | Create container
|
||||||
|
containers.podman.podman_container:
|
||||||
|
debug: no
|
||||||
|
image: "{{ wikijs_image }}:{{ wikijs_version }}"
|
||||||
|
image_strict: yes
|
||||||
|
recreate: yes
|
||||||
|
state: present
|
||||||
|
name: "{{ wikijs_name }}"
|
||||||
|
env: "{{ wikijs_config }}"
|
||||||
|
volume: "{{ wikijs_volumes }}"
|
||||||
|
ports: "{{ wikijs_ports }}"
|
||||||
|
register: podman_output
|
||||||
|
|
||||||
|
- ansible.builtin.debug:
|
||||||
|
var: podman_output
|
24
tasks/systemd.yml
Normal file
24
tasks/systemd.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Wiki.js | Generate systemd unit file for the container(s)
|
||||||
|
containers.podman.podman_generate_systemd:
|
||||||
|
name: wikijs
|
||||||
|
dest: ~/.config/systemd/user/
|
||||||
|
restart_policy: on-failure
|
||||||
|
restart_sec: 60
|
||||||
|
|
||||||
|
- name: Wiki.js | Ensure container(s) are enabled in systemd, but stop it now because we wanted to use "recreate" in the podman_container task before this.
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: container-wikijs
|
||||||
|
scope: user
|
||||||
|
daemon_reload: true
|
||||||
|
state: stopped
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
- name: Wiki.js | Start the container(s) with systemd, so systemd will know the state of the container(s) moving forward.
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: container-wikijs
|
||||||
|
scope: user
|
||||||
|
state: started
|
||||||
|
register: systemd_result
|
||||||
|
until: systemd_result is succeeded
|
||||||
|
retries: 1
|
2
tests/inventory
Normal file
2
tests/inventory
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
6
tests/test.yml
Normal file
6
tests/test.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
connection: local
|
||||||
|
roles:
|
||||||
|
- wikijs
|
Loading…
Reference in New Issue
Block a user