mirror of
https://git.lapiole.org/dani/ansible-roles.git
synced 2025-07-27 00:05:44 +02:00
Update to 2021-12-01 19:13
This commit is contained in:
35
roles/documize/defaults/main.yml
Normal file
35
roles/documize/defaults/main.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
|
||||
# Version of cocumize to deploy
|
||||
documize_version: 4.1.1
|
||||
# URL of the binary to install
|
||||
documize_bin_url: https://github.com/documize/community/releases/download/v{{ documize_version }}/documize-community-linux-amd64
|
||||
# Expected sha1 of the binary
|
||||
documize_bin_sha1: 7362cb0b0479b1315399df86fabef81aa1a43124
|
||||
|
||||
# Should documize handle upgrades or only initial install ?
|
||||
documize_manage_upgrade: True
|
||||
|
||||
# Root directory where documize will be installed
|
||||
documize_root_dir: /opt/documize
|
||||
|
||||
# User under which documize will run
|
||||
documize_user: documize
|
||||
|
||||
# port on which documize will listen
|
||||
documize_port: 5001
|
||||
|
||||
# List of IP / CIDR allowed to access documize port
|
||||
documize_src_ip: []
|
||||
|
||||
# Database settings
|
||||
documize_db_engine: 'mysql'
|
||||
documize_db_server: "{{ (documize_db_engine == 'postgres') | ternary(pg_server,mysql_server) | default('localhost') }}"
|
||||
documize_db_port: "{{ (documize_db_engine == 'postgres') | ternary('5432','3306') }}"
|
||||
documize_db_user: documize
|
||||
documize_db_name: documize
|
||||
# If password is not defined, a random one will be generated and stored in meta/ansible_dbpass
|
||||
# documize_db_pass: S3Cr3t.
|
||||
|
||||
# Salt for documize. A random one will be generated if not defined
|
||||
# documize_salt: tsu3Acndky8cdTNx3
|
5
roles/documize/handlers/main.yml
Normal file
5
roles/documize/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: restart documize
|
||||
service: name=documize state=restarted
|
||||
when: not documize_started.changed
|
8
roles/documize/meta/main.yml
Normal file
8
roles/documize/meta/main.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
allow_duplicates: True
|
||||
dependencies:
|
||||
- role: mysql_server
|
||||
when: documize_db_engine == 'mysql' and documize_db_server in ['127.0.0.1','localhost']
|
||||
- role: postgresql_server
|
||||
when: documize_db_engine == 'postgres' and documize_db_server in ['127.0.0.1','localhost']
|
10
roles/documize/tasks/archive_post.yml
Normal file
10
roles/documize/tasks/archive_post.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
|
||||
- name: Compress previous version
|
||||
command: tar cf {{ documize_root_dir }}/archives/{{ documize_current_version }}.tar.zst --use-compress-program=zstd ./
|
||||
args:
|
||||
chdir: "{{ documize_root_dir }}/archives/{{ documize_current_version }}"
|
||||
warn: False
|
||||
environment:
|
||||
ZSTD_CLEVEL: 10
|
||||
tags: documize
|
41
roles/documize/tasks/archive_pre.yml
Normal file
41
roles/documize/tasks/archive_pre.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
|
||||
- name: Create the archive dir
|
||||
file: path={{ documize_root_dir }}/archives/{{ documize_current_version }} state=directory
|
||||
tags: documize
|
||||
|
||||
- name: Backup previous version
|
||||
copy: src={{ documize_root_dir }}/bin/documize dest={{ documize_root_dir }}/archives/{{ documize_current_version }}/ remote_src=True
|
||||
tags: documize
|
||||
|
||||
- name: Backup the database
|
||||
command: >
|
||||
/usr/pgsql-14/bin/pg_dump
|
||||
--clean
|
||||
--create
|
||||
--host={{ documize_db_server }}
|
||||
--port={{ documize_db_port }}
|
||||
--username={{ documize_db_user }}
|
||||
{{ documize_db_name }}
|
||||
--file={{ documize_root_dir }}/archives/{{ documize_current_version }}/{{ documize_db_name }}.sql
|
||||
environment:
|
||||
- PGPASSWORD: "{{ documize_db_pass }}"
|
||||
when: documize_db_engine == 'postgres'
|
||||
tags: documize
|
||||
|
||||
- name: Archive the database
|
||||
mysql_db:
|
||||
state: dump
|
||||
name: "{{ documize_db_name }}"
|
||||
target: "{{ documize_root_dir }}/archives/{{ documize_current_version }}/{{ documize_db_name }}.sql.xz"
|
||||
login_host: "{{ documize_db_server | default(mysql_server) }}"
|
||||
login_user: sqladmin
|
||||
login_password: "{{ mysql_admin_pass }}"
|
||||
quick: True
|
||||
single_transaction: True
|
||||
environment:
|
||||
XZ_OPT: -T0
|
||||
when: documize_db_engine == 'mysql'
|
||||
tags: documize
|
||||
|
||||
|
7
roles/documize/tasks/cleanup.yml
Normal file
7
roles/documize/tasks/cleanup.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- name: Remove tmp and obsolete files
|
||||
file: path={{ item }} state=absent
|
||||
loop:
|
||||
- "{{ documize_root_dir }}/archives/{{ documize_current_version }}"
|
||||
tags: documize
|
6
roles/documize/tasks/conf.yml
Normal file
6
roles/documize/tasks/conf.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
- name: Deploy documize configuration
|
||||
template: src=documize.conf.j2 dest={{ documize_root_dir }}/etc/documize.conf group={{ documize_user }} mode=640
|
||||
notify: restart documize
|
||||
tags: documize
|
20
roles/documize/tasks/directories.yml
Normal file
20
roles/documize/tasks/directories.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
|
||||
- name: Create needed directories
|
||||
file: path={{ item.dir }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }}
|
||||
loop:
|
||||
- dir: "{{ documize_root_dir }}"
|
||||
- dir: "{{ documize_root_dir }}/tmp"
|
||||
group: "{{ documize_user }}"
|
||||
mode: 770
|
||||
- dir: "{{ documize_root_dir }}/bin"
|
||||
- dir: "{{ documize_root_dir }}/etc"
|
||||
group: "{{ documize_user }}"
|
||||
mode: 750
|
||||
- dir: "{{ documize_root_dir }}/meta"
|
||||
mode: 700
|
||||
- dir: "{{ documize_root_dir }}/backup"
|
||||
mode: 700
|
||||
- dir: "{{ documize_root_dir }}/archives"
|
||||
mode: 700
|
||||
tags: documize
|
33
roles/documize/tasks/facts.yml
Normal file
33
roles/documize/tasks/facts.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
|
||||
# Detect installed version (if any)
|
||||
- block:
|
||||
- import_tasks: ../includes/webapps_set_install_mode.yml
|
||||
vars:
|
||||
- root_dir: "{{ documize_root_dir }}"
|
||||
- version: "{{ documize_version }}"
|
||||
- set_fact: documize_install_mode={{ (install_mode == 'upgrade' and not documize_manage_upgrade) | ternary('none',install_mode) }}
|
||||
- set_fact: documize_current_version={{ current_version | default('') }}
|
||||
tags: documize
|
||||
|
||||
# Create a random pass for the DB if needed
|
||||
- block:
|
||||
- import_tasks: ../includes/get_rand_pass.yml
|
||||
vars:
|
||||
- pass_file: "{{ documize_root_dir }}/meta/ansible_db_pass"
|
||||
- complex: False
|
||||
- set_fact: documize_db_pass={{ rand_pass }}
|
||||
when: documize_db_pass is not defined
|
||||
tags: documize
|
||||
|
||||
# Create a random salt if needed
|
||||
- block:
|
||||
- import_tasks: ../includes/get_rand_pass.yml
|
||||
vars:
|
||||
- pass_file: "{{ documize_root_dir }}/meta/ansible_salt"
|
||||
- complex: False
|
||||
- pass_size: 17
|
||||
- set_fact: documize_salt={{ rand_pass }}
|
||||
when: documize_salt is not defined
|
||||
tags: documize
|
||||
|
72
roles/documize/tasks/install.yml
Normal file
72
roles/documize/tasks/install.yml
Normal file
@@ -0,0 +1,72 @@
|
||||
---
|
||||
|
||||
- name: Install needed tools
|
||||
package:
|
||||
name:
|
||||
- tar
|
||||
- zstd
|
||||
- postgresql14
|
||||
tags: documize
|
||||
|
||||
- name: Download documize
|
||||
get_url:
|
||||
url: "{{ documize_bin_url }}"
|
||||
dest: "{{ documize_root_dir }}/bin/documize"
|
||||
checksum: sha1:{{ documize_bin_sha1 }}
|
||||
mode: 755
|
||||
when: documize_install_mode != 'none'
|
||||
notify: restart documize
|
||||
tags: documize
|
||||
|
||||
- name: Install systemd unit
|
||||
template: src=documize.service.j2 dest=/etc/systemd/system/documize.service
|
||||
notify: restart documize
|
||||
register: documize_unit
|
||||
tags: documize
|
||||
|
||||
- name: Reload systemd
|
||||
systemd: daemon_reload=True
|
||||
when: documize_unit.changed
|
||||
tags: documize
|
||||
|
||||
- when: documize_db_engine == 'postgres'
|
||||
block:
|
||||
- name: Create the PostgreSQL role
|
||||
postgresql_user:
|
||||
db: postgres
|
||||
name: "{{ miniflux_db_user }}"
|
||||
password: "{{ miniflux_db_pass }}"
|
||||
login_host: "{{ miniflux_db_server }}"
|
||||
login_user: sqladmin
|
||||
login_password: "{{ pg_admin_pass }}"
|
||||
|
||||
- name: Create the PostgreSQL database
|
||||
postgresql_db:
|
||||
name: "{{ miniflux_db_name }}"
|
||||
encoding: UTF-8
|
||||
lc_collate: C
|
||||
lc_ctype: C
|
||||
template: template0
|
||||
owner: "{{ miniflux_db_user }}"
|
||||
login_host: "{{ miniflux_db_server }}"
|
||||
login_user: sqladmin
|
||||
login_password: "{{ pg_admin_pass }}"
|
||||
|
||||
tags: miniflux
|
||||
|
||||
# Create MySQL database
|
||||
- when: documize_db_engine == 'mysql'
|
||||
import_tasks: ../includes/webapps_create_mysql_db.yml
|
||||
vars:
|
||||
- db_name: "{{ documize_db_name }}"
|
||||
- db_user: "{{ documize_db_user }}"
|
||||
- db_server: "{{ documize_db_server }}"
|
||||
- db_pass: "{{ documize_db_pass }}"
|
||||
tags: documize
|
||||
|
||||
- name: Deploy backup hooks
|
||||
template: src={{ item }}-backup.j2 dest=/etc/backup/{{ item }}.d/documize mode=700
|
||||
loop:
|
||||
- pre
|
||||
- post
|
||||
tags: documize
|
8
roles/documize/tasks/iptables.yml
Normal file
8
roles/documize/tasks/iptables.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
- name: Handle documize port in the firewall
|
||||
iptables_raw:
|
||||
name: documize_port
|
||||
state: "{{ (documize_src_ip | length > 0) | ternary('present','absent') }}"
|
||||
rules: "-A INPUT -m state --state NEW -p tcp --dport {{ documize_port }} -s {{ documize_src_ip | join(',') }} -j ACCEPT"
|
||||
tags: firewall,documize
|
16
roles/documize/tasks/main.yml
Normal file
16
roles/documize/tasks/main.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
- include: user.yml
|
||||
- include: directories.yml
|
||||
- include: facts.yml
|
||||
- include: archive_pre.yml
|
||||
when: documize_install_mode == 'upgrade'
|
||||
- include: install.yml
|
||||
- include: conf.yml
|
||||
- include: iptables.yml
|
||||
when: iptables_manage | default(True)
|
||||
- include: services.yml
|
||||
- include: write_version.yml
|
||||
- include: archive_post.yml
|
||||
when: documize_install_mode == 'upgrade'
|
||||
- include: cleanup.yml
|
7
roles/documize/tasks/services.yml
Normal file
7
roles/documize/tasks/services.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- name: Start and enable the service
|
||||
service: name=documize state=started enabled=True
|
||||
register: documize_started
|
||||
tags: documize
|
||||
|
5
roles/documize/tasks/user.yml
Normal file
5
roles/documize/tasks/user.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Create user account
|
||||
user: name={{ documize_user }} system=True shell=/sbin/nologin home={{ documize_root_dir }}
|
||||
tags: documize
|
5
roles/documize/tasks/write_version.yml
Normal file
5
roles/documize/tasks/write_version.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Write installed version
|
||||
copy: content={{ documize_version }} dest={{ documize_root_dir }}/meta/ansible_version
|
||||
tags: documize
|
15
roles/documize/templates/documize.conf.j2
Normal file
15
roles/documize/templates/documize.conf.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
[http]
|
||||
port = {{ documize_port }}
|
||||
|
||||
[database]
|
||||
{% if documize_db_engine == 'mysql' %}
|
||||
type = "mysql"
|
||||
connection = "{{ documize_db_user }}:{{ documize_db_pass }}@tcp({{ documize_db_server }}:{{ documize_db_port }})/{{ documize_db_name }}"
|
||||
{% elif documize_db_engine == 'postgres' %}
|
||||
type = "postgresql"
|
||||
connection = "host={{ documize_db_server }} port={{ documize_db_port }} dbname={{ documize_db_name }} user={{ documize_db_user }} password={{ documize_db_pass }} sslmode=disable"
|
||||
{% endif %}
|
||||
salt = "{{ documize_salt }}"
|
||||
|
||||
[install]
|
||||
location = "selfhost"
|
24
roles/documize/templates/documize.service.j2
Normal file
24
roles/documize/templates/documize.service.j2
Normal file
@@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=Documize Documentation Manager
|
||||
After=network.target postgresql.service mariadb.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ documize_user }}
|
||||
ExecStart={{ documize_root_dir }}/bin/documize {{ documize_root_dir }}/etc/documize.conf
|
||||
WorkingDirectory={{ documize_root_dir }}/tmp
|
||||
Restart=always
|
||||
NoNewPrivileges=true
|
||||
PrivateDevices=true
|
||||
ProtectControlGroups=true
|
||||
ProtectHome=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectSystem=strict
|
||||
RestrictRealtime=true
|
||||
ReadWritePaths=/run
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
3
roles/documize/templates/post-backup.j2
Normal file
3
roles/documize/templates/post-backup.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
rm -f {{ documize_root_dir }}/backup/*
|
26
roles/documize/templates/pre-backup.j2
Normal file
26
roles/documize/templates/pre-backup.j2
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
{% if documize_db_engine == 'mysql' %}
|
||||
/usr/bin/mysqldump \
|
||||
{% if documize_db_server not in ['127.0.0.1','localhost'] %}
|
||||
--user={{ documize_db_user | quote }} \
|
||||
--password={{ documize_db_pass | quote }} \
|
||||
--host={{ documize_db_server | quote }} \
|
||||
{% endif %}
|
||||
--quick --single-transaction \
|
||||
--add-drop-table {{ documize_db_name | quote }} | zstd -c > "{{ documize_root_dir }}/backup/{{ documize_db_name }}.sql.zst"
|
||||
{% elif documize_db_engine == 'postgres' %}
|
||||
{% if documize_db_server not in ['127.0.0.1','localhost'] %}
|
||||
PGPASSWORD={{ documize_db_pass | quote }} /usr/pgsql-14/bin/pg_dump \
|
||||
--clean \
|
||||
--create \
|
||||
--username={{ documize_db_user | quote }} \
|
||||
--host={{ documize_db_server | quote }} \
|
||||
{{ documize_db_name | quote }} | \
|
||||
{% else %}
|
||||
su - postgres -c "/usr/pgsql-14/bin/pg_dump --clean --create {{ documize_db_name | quote }}" | \
|
||||
{% endif %}
|
||||
zstd -c > "{{ documize_root_dir }}/backup/{{ documize_db_name }}.sql.zst"
|
||||
{% endif %}
|
Reference in New Issue
Block a user