mirror of
https://git.lapiole.org/dani/ansible-roles.git
synced 2025-07-26 15:55:56 +02:00
Update to 2021-12-01 19:13
This commit is contained in:
10
roles/bookstack/tasks/archive_post.yml
Normal file
10
roles/bookstack/tasks/archive_post.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
|
||||
- name: Compress previous version
|
||||
command: tar cf {{ bookstack_root_dir }}/archives/{{ bookstack_current_version }}.tar.zst ./ --use-compress-program=zstd
|
||||
args:
|
||||
chdir: "{{ bookstack_root_dir }}/archives/{{ bookstack_current_version }}"
|
||||
warn: False
|
||||
environment:
|
||||
ZSTD_CLEVEL: 10
|
||||
tags: bookstack
|
31
roles/bookstack/tasks/archive_pre.yml
Normal file
31
roles/bookstack/tasks/archive_pre.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
|
||||
- name: Create the archive dir
|
||||
file: path={{ bookstack_root_dir }}/archives/{{ bookstack_current_version }} state=directory
|
||||
tags: bookstack
|
||||
|
||||
- name: Archive current version
|
||||
synchronize:
|
||||
src: "{{ bookstack_root_dir }}/app"
|
||||
dest: "{{ bookstack_root_dir }}/archives/{{ bookstack_current_version }}/"
|
||||
compress: False
|
||||
delete: True
|
||||
rsync_opts:
|
||||
- '--exclude=/storage/'
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
tags: bookstack
|
||||
|
||||
- name: Dump the database
|
||||
mysql_db:
|
||||
state: dump
|
||||
name: "{{ bookstack_db_name }}"
|
||||
target: "{{ bookstack_root_dir }}/archives/{{ bookstack_current_version }}/{{ bookstack_db_name }}.sql.xz"
|
||||
login_host: "{{ bookstack_db_server }}"
|
||||
login_user: "{{ bookstack_db_user }}"
|
||||
login_password: "{{ bookstack_db_pass }}"
|
||||
quick: True
|
||||
single_transaction: True
|
||||
environment:
|
||||
XZ_OPT: -T0
|
||||
tags: bookstack
|
||||
|
9
roles/bookstack/tasks/cleanup.yml
Normal file
9
roles/bookstack/tasks/cleanup.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
|
||||
- name: Remove tmp and obsolete files
|
||||
file: path={{ item }} state=absent
|
||||
loop:
|
||||
- "{{ bookstack_root_dir }}/archives/{{ bookstack_current_version }}"
|
||||
- "{{ bookstack_root_dir }}/tmp/BookStack-{{ bookstack_version }}"
|
||||
- "{{ bookstack_root_dir }}/tmp/BookStack-{{ bookstack_version }}.tar.gz"
|
||||
tags: bookstack
|
54
roles/bookstack/tasks/conf.yml
Normal file
54
roles/bookstack/tasks/conf.yml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
|
||||
- import_tasks: ../includes/webapps_webconf.yml
|
||||
vars:
|
||||
- app_id: bookstack_{{ bookstack_id }}
|
||||
- php_version: "{{ bookstack_php_version }}"
|
||||
- php_fpm_pool: "{{ bookstack_php_fpm_pool | default('') }}"
|
||||
tags: bookstack
|
||||
|
||||
- when: bookstack_app_key is not defined
|
||||
block:
|
||||
- name: Generate a uniq application key
|
||||
shell: /bin/php{{ bookstack_php_version }} {{ bookstack_root_dir }}/app/artisan key:generate --show > {{ bookstack_root_dir }}/meta/ansible_app_key
|
||||
args:
|
||||
creates: "{{ bookstack_root_dir }}/meta/ansible_app_key"
|
||||
|
||||
- name: Read application key
|
||||
slurp: src={{ bookstack_root_dir }}/meta/ansible_app_key
|
||||
register: bookstack_rand_app_key
|
||||
|
||||
- set_fact: bookstack_app_key={{ bookstack_rand_app_key.content | b64decode | trim }}
|
||||
|
||||
tags: bookstack
|
||||
|
||||
- name: Deploy BookStack configuration
|
||||
template: src=env.j2 dest={{ bookstack_root_dir }}/app/.env group={{ bookstack_php_user }} mode=640
|
||||
tags: bookstack
|
||||
|
||||
- when: bookstack_install_mode != 'none'
|
||||
block:
|
||||
- name: Migrate the database
|
||||
shell: echo yes | /bin/php{{ bookstack_php_version }} {{ bookstack_root_dir }}/app/artisan migrate
|
||||
|
||||
- name: Clear cache
|
||||
command: /bin/php{{ bookstack_php_version }} {{ bookstack_root_dir }}/app/artisan cache:clear
|
||||
|
||||
- name: Clear views
|
||||
command: /bin/php{{ bookstack_php_version }} {{ bookstack_root_dir }}/app/artisan view:clear
|
||||
|
||||
- name: Regenerate search
|
||||
command: /bin/php{{ bookstack_php_version }} {{ bookstack_root_dir }}/app/artisan bookstack:regenerate-search
|
||||
|
||||
become_user: "{{ bookstack_php_user }}"
|
||||
tags: bookstack
|
||||
|
||||
- name: Deploy permission script
|
||||
template: src=perms.sh.j2 dest={{ bookstack_root_dir }}/perms.sh mode=755
|
||||
register: bookstack_perm_script
|
||||
tags: bookstack
|
||||
|
||||
- name: Apply permissions
|
||||
command: "{{ bookstack_root_dir }}/perms.sh"
|
||||
when: bookstack_perm_script.changed or bookstack_install_mode != 'none'
|
||||
tags: bookstack
|
23
roles/bookstack/tasks/directories.yml
Normal file
23
roles/bookstack/tasks/directories.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: Create required directories
|
||||
file: path={{ item.dir }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }}
|
||||
loop:
|
||||
- dir: "{{ bookstack_root_dir }}"
|
||||
- dir: "{{ bookstack_root_dir }}/meta"
|
||||
mode: 700
|
||||
- dir: "{{ bookstack_root_dir }}/backup"
|
||||
mode: 700
|
||||
- dir: "{{ bookstack_root_dir }}/archives"
|
||||
mode: 700
|
||||
- dir: "{{ bookstack_root_dir }}/app"
|
||||
- dir: "{{ bookstack_root_dir }}/sessions"
|
||||
group: "{{ bookstack_php_user }}"
|
||||
mode: 770
|
||||
- dir: "{{ bookstack_root_dir }}/tmp"
|
||||
group: "{{ bookstack_php_user }}"
|
||||
mode: 770
|
||||
- dir: "{{ bookstack_root_dir }}/data"
|
||||
group: "{{ bookstack_php_user }}"
|
||||
mod: 700
|
||||
tags: bookstack
|
20
roles/bookstack/tasks/facts.yml
Normal file
20
roles/bookstack/tasks/facts.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
|
||||
# Detect installed version (if any)
|
||||
- block:
|
||||
- import_tasks: ../includes/webapps_set_install_mode.yml
|
||||
vars:
|
||||
- root_dir: "{{ bookstack_root_dir }}"
|
||||
- version: "{{ bookstack_version }}"
|
||||
- set_fact: bookstack_install_mode={{ (install_mode == 'upgrade' and not bookstack_manage_upgrade) | ternary('none',install_mode) }}
|
||||
- set_fact: bookstack_current_version={{ current_version | default('') }}
|
||||
tags: bookstack
|
||||
|
||||
# Create a random pass for the DB if needed
|
||||
- block:
|
||||
- import_tasks: ../includes/get_rand_pass.yml
|
||||
vars:
|
||||
- pass_file: "{{ bookstack_root_dir }}/meta/ansible_dbpass"
|
||||
- set_fact: bookstack_db_pass={{ rand_pass }}
|
||||
when: bookstack_db_pass is not defined
|
||||
tags: bookstack
|
86
roles/bookstack/tasks/install.yml
Normal file
86
roles/bookstack/tasks/install.yml
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
|
||||
- name: Install needed tools
|
||||
package:
|
||||
name:
|
||||
- acl
|
||||
- tar
|
||||
- zstd
|
||||
- mariadb
|
||||
tags: bookstack
|
||||
|
||||
- when: bookstack_install_mode != 'none'
|
||||
block:
|
||||
- name: Download bookstack
|
||||
get_url:
|
||||
url: "{{ bookstack_archive_url }}"
|
||||
dest: "{{ bookstack_root_dir }}/tmp"
|
||||
checksum: sha1:{{ bookstack_archive_sha1 }}
|
||||
|
||||
- name: Extract the archive
|
||||
unarchive:
|
||||
src: "{{ bookstack_root_dir }}/tmp/BookStack-{{ bookstack_version }}.tar.gz"
|
||||
dest: "{{ bookstack_root_dir }}/tmp"
|
||||
remote_src: True
|
||||
|
||||
- name: Move BookStack to its final dir
|
||||
synchronize:
|
||||
src: "{{ bookstack_root_dir }}/tmp/BookStack-{{ bookstack_version }}/"
|
||||
dest: "{{ bookstack_root_dir }}/app/"
|
||||
delete: True
|
||||
compress: False
|
||||
rsync_opts:
|
||||
- '--exclude=/storage/'
|
||||
- '--exclude=/public/uploads/'
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
|
||||
- name: Populate data directories
|
||||
synchronize:
|
||||
src: "{{ bookstack_root_dir }}/tmp/BookStack-{{ bookstack_version }}/{{ item }}"
|
||||
dest: "{{ bookstack_root_dir }}/data/"
|
||||
compress: False
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
loop:
|
||||
- storage
|
||||
- public/uploads
|
||||
|
||||
- name: Link data directories
|
||||
file: src={{ item.src }} dest={{ item.dest }} state=link
|
||||
loop:
|
||||
- src: "{{ bookstack_root_dir }}/data/storage"
|
||||
dest: "{{ bookstack_root_dir }}/app/storage"
|
||||
- src: "{{ bookstack_root_dir }}/data/uploads"
|
||||
dest: "{{ bookstack_root_dir }}/app/public/uploads"
|
||||
|
||||
- name: Install PHP libs with composer
|
||||
composer:
|
||||
command: install
|
||||
working_dir: "{{ bookstack_root_dir }}/app"
|
||||
executable: /bin/php{{ bookstack_php_version }}
|
||||
environment:
|
||||
php: /bin/php{{ bookstack_php_version }}
|
||||
|
||||
tags: bookstack
|
||||
|
||||
- import_tasks: ../includes/webapps_create_mysql_db.yml
|
||||
vars:
|
||||
- db_name: "{{ bookstack_db_name }}"
|
||||
- db_user: "{{ bookstack_db_user }}"
|
||||
- db_server: "{{ bookstack_db_server }}"
|
||||
- db_pass: "{{ bookstack_db_pass }}"
|
||||
tags: bookstack
|
||||
|
||||
- name: Set correct SELinux context
|
||||
sefcontext:
|
||||
target: "{{ bookstack_root_dir }}(/.*)?"
|
||||
setype: httpd_sys_content_t
|
||||
state: present
|
||||
when: ansible_selinux.status == 'enabled'
|
||||
tags: bookstack
|
||||
|
||||
- name: Install pre/post backup hooks
|
||||
template: src={{ item }}-backup.j2 dest=/etc/backup/{{ item }}.d/bookstack_{{ bookstack_id }} mode=700
|
||||
loop:
|
||||
- pre
|
||||
- post
|
||||
tags: bookstack
|
13
roles/bookstack/tasks/main.yml
Normal file
13
roles/bookstack/tasks/main.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
|
||||
- include: user.yml
|
||||
- include: directories.yml
|
||||
- include: facts.yml
|
||||
- include: archive_pre.yml
|
||||
when: bookstack_install_mode == 'upgrade'
|
||||
- include: install.yml
|
||||
- include: conf.yml
|
||||
- include: write_version.yml
|
||||
- include: archive_post.yml
|
||||
when: bookstack_install_mode == 'upgrade'
|
||||
- include: cleanup.yml
|
5
roles/bookstack/tasks/user.yml
Normal file
5
roles/bookstack/tasks/user.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Create user account
|
||||
user: name={{ bookstack_php_user }} system=True shell=/sbin/nologin home={{ bookstack_root_dir }}
|
||||
tags: bookstack
|
5
roles/bookstack/tasks/write_version.yml
Normal file
5
roles/bookstack/tasks/write_version.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Write current version
|
||||
copy: content={{ bookstack_version }} dest={{ bookstack_root_dir }}/meta/ansible_version
|
||||
tags: bookstack
|
Reference in New Issue
Block a user