- hosts: localhost vars: meta: application_name: BookStack playbook_version: 0.2 app_installation_path: "/var/www/virtual/{{ uberspace_asteroid_name }}/bookstack" app_public_docroot: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" app_domain: "{{ uberspace_default_web_domain }}" app_db_name: "{{ uberspace_asteroid_name }}_bookstack" app_mail_from_name: BookStack _app_env_configuration: APP_URL : "https://{{ app_domain }}" DB_HOST: localhost DB_DATABASE: "{{ app_db_name }}" DB_USERNAME: "{{ uberspace_asteroid_name }}" DB_PASSWORD: "{{ uberspace_mariadb_password }}" MAIL_DRIVER: sendmail MAIL_FROM_NAME: "{{ app_mail_from_name }}" MAIL_FROM: "sysmail@{{ uberspace_default_web_domain }}" MAIL_SENDMAIL_COMMAND: "'/usr/bin/sendmail -t'" app_admin_username: "{{ uberspace_asteroid_name }}" app_admin_mailaddress: "{{ uberspace_mail_sysmail }}" app_admin_password: RANDOM _app_admin_password_random: "{{ lookup('ansible.builtin.password', '/dev/null length=20 chars=ascii_letters,digits') }}" _app_admin_password_final: "{{ (app_admin_password=='RANDOM') | ternary(_app_admin_password_random, app_admin_password) }}" tasks: - name: _Return resolved playbook vars debug: var: vars tags: - playbook-vars - name: Create installation path file: path: "{{ app_installation_path }}" state: directory - name: Check if installation path is empty find: paths: "{{ app_installation_path }}" hidden: true file_type: any register: files_in_installation_path - name: Ensure that installation path is empty assert: that: - files_in_installation_path.matched == 0 fail_msg: "Installation path '{{ app_installation_path }}' is not empty" - name: Check if public docroot path is empty find: paths: "{{ app_public_docroot }}" hidden: true file_type: any excludes: nocontent.html register: files_in_installation_path - name: Ensure that public docroot path is empty assert: that: - files_in_installation_path.matched == 0 fail_msg: "Installation path '{{ app_public_docroot }}' is not empty" - name: Add domain to Asteroid uberspace.api.web_domain: data: name: "{{ app_domain }}" state: present register: asteroid_domain - name: Select PHP 8.4 command: argv: [uberspace, tool, php, version, set, "8.4"] - name: Clone the latest stable BookStack release git: repo: https://source.bookstackapp.com/bookstack.git dest: "{{ app_installation_path }}" version: release single_branch: true depth: 1 - name: Install dependencies with composer when: not ansible_check_mode command: cmd: composer install --no-dev --no-interaction --prefer-dist chdir: "{{ app_installation_path }}" - name: Create MariaDB database ansible.mariadb.mariadb_db: name: "{{ app_db_name }}" state: present - name: Copy env config file when: not ansible_check_mode copy: src: "{{ app_installation_path }}/.env.example" remote_src: true dest: "{{ app_installation_path }}/.env" mode: '0600' - name: _Write configuration to env file no_log: true when: not ansible_check_mode lineinfile: path: "{{ app_installation_path }}/.env" regex: '^{{ item.key }}\s*=\s*.*$' line: "{{ item.key }}={{ item.value }}" state: present loop: "{{ _app_env_configuration | default({}) | dict2items }}" loop_control: label: "{{ item.key }}" # only key, to redact secrets - name: _Generate security key no_log: true when: not ansible_check_mode command: cmd: /usr/bin/php artisan key:generate --force chdir: "{{ app_installation_path }}" - name: Add symlink for log to '~/logs' when: not ansible_check_mode file: src: "{{ app_installation_path }}/storage/logs/laravel.log" dest: "~/logs/bookstack.log" force: true state: link - name: Migrate DB when: not ansible_check_mode command: cmd: /usr/bin/php artisan migrate --no-interaction --force chdir: "{{ app_installation_path }}" - name: _Resolve administrator password once set_fact: _resolved_password: "{{ _app_admin_password_final }}" no_log: true - name: _Setup admin user no_log: true when: not ansible_check_mode command: cmd: > /usr/bin/php artisan bookstack:create-admin --name {{ app_admin_username }} --email {{ app_admin_mailaddress }} --password {{ _resolved_password }} --initial chdir: "{{ app_installation_path }}" - name: _Save administrator password privately copy: dest: "/home/{{ uberspace_asteroid_name }}/bookstack-admin-password" content: "{{ _resolved_password }}\n" mode: '0600' no_log: true - name: Remove html dir file: path: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" state: absent - name: Create html symlink to bookstack public when: not ansible_check_mode file: src: "{{ app_installation_path }}/public" dest: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" state: link - name: Route the domain to Apache command: argv: [uberspace, web, backend, add, "{{ app_domain }}/", apache, --force, --wait] - name: Check public login page uri: url: "https://{{ app_domain }}/login" register: health until: health.status == 200 retries: 12 delay: 5 - name: _Report debug: msg: > BookStack has been successfully installed in: '{{ app_installation_path }}' for your domain: '{{ app_domain }}' An admin user has been created with the following data: username: '{{ app_admin_username }}' mailaddress: '{{ app_admin_mailaddress }}' {% if app_admin_password != 'RANDOM' %} password: '(your provided password)' {% else %} Read your password from ~/bookstack-admin-password, then remove that file after saving it securely. {% endif %}