- hosts: localhost vars: meta: application_name: Etherpad playbook_version: 0.1 app_domain: "{{ uberspace_default_web_domain }}" app_db_name: "{{ uberspace_asteroid_name }}_etherpad" app_admin_username: "{{ uberspace_asteroid_name }}" app_port: 9001 _home: "/home/{{ uberspace_asteroid_name }}" _root: "{{ _home }}/opt/etherpad" tasks: # Required by `uberspace app install`; skipped during installation. - name: _Return resolved playbook vars debug: var: vars tags: [playbook-vars] - name: Validate installation options assert: that: - app_domain is match('^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$') - app_db_name is match('^[a-zA-Z0-9_]+$') - app_db_name | length <= 64 - app_db_name.startswith(uberspace_asteroid_name + '_') - app_admin_username is match('^[a-zA-Z0-9]+([_.-][a-zA-Z0-9]+)*$') - app_port | string is match('^[0-9]+$') - app_port | int >= 1024 - app_port | int <= 65535 - uberspace_mariadb_password | default('') | length > 0 fail_msg: "Use an account-prefixed database, an admin username and a port from 1024 to 65535. The installer must supply your MariaDB password." - name: Inspect installation and service paths stat: path: "{{ item }}" loop: - "{{ _root }}" - "{{ _home }}/.config/systemd/user/etherpad.service" register: existing - name: Refuse to overwrite an existing installation or service assert: that: not item.stat.exists fail_msg: "{{ item.item }} already exists. This playbook only supports fresh installations." loop: "{{ existing.results }}" loop_control: label: "{{ item.item }}" - name: Inspect the document root find: paths: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" hidden: true file_type: any excludes: [nocontent.html] register: contents - name: Require an empty document root assert: that: contents.matched == 0 fail_msg: "Use a fresh Asteroid with an empty document root." - name: List existing databases command: argv: [mariadb, --batch, --skip-column-names, --execute=SHOW DATABASES] register: databases changed_when: false check_mode: false - name: Refuse to reuse an existing database assert: that: app_db_name not in databases.stdout_lines fail_msg: "Database {{ app_db_name }} already exists. Choose a new db_name." - name: Inspect existing web routes command: argv: [uberspace, web, backend, list, --json] register: routes changed_when: false check_mode: false - name: Refuse to replace another application's route assert: that: item.path != '/' or item.destination == 'APACHE' fail_msg: "{{ app_domain }}/ already serves another backend." loop: "{{ (routes.stdout | from_json) | selectattr('domain', 'equalto', app_domain) | list }}" loop_control: label: "{{ item.path }}" - name: Require an unused HTTP port wait_for: host: 127.0.0.1 port: "{{ app_port }}" state: stopped timeout: 1 when: not ansible_check_mode - name: List registered web domains command: argv: [uberspace, web, domain, list, --json] register: domains changed_when: false check_mode: false # Preflight checks run in check mode; dependent mutations do not. - name: Install Etherpad when: not ansible_check_mode block: - name: Find the latest stable Etherpad release uri: url: https://api.github.com/repos/ether/etherpad/releases/latest return_content: true register: release - name: Validate the release assert: that: - not release.json.draft - not release.json.prerelease - release.json.tag_name is match('^v[0-9]+\.[0-9]+\.[0-9]+$') - name: Select Node.js 24 command: argv: [uberspace, tool, nodejs, version, set, '24'] - name: Create the private application parent directory file: path: "{{ _home }}/opt" state: directory mode: '0700' - name: Clone the resolved release git: repo: https://github.com/ether/etherpad.git dest: "{{ _root }}" version: "{{ release.json.tag_name }}" depth: 1 - name: Install dependencies from the lockfile command: argv: [pnpm, install, --recursive, --frozen-lockfile] chdir: "{{ _root }}" - name: Build the editor and administration interface command: argv: [pnpm, run, 'build:etherpad'] chdir: "{{ _root }}" - name: Create the MariaDB database ansible.mariadb.mariadb_db: name: "{{ app_db_name }}" encoding: utf8mb4 collation: utf8mb4_bin state: present - name: _Write private Etherpad configuration copy: dest: "{{ _root }}/settings.json" mode: '0600' content: | { "title": "Etherpad", "ip": "0.0.0.0", "port": {{ app_port | int }}, "trustProxy": true, "dbType": "mysql", "dbSettings": { "host": "127.0.0.1", "port": 3306, "user": {{ uberspace_asteroid_name | to_json }}, "password": {{ uberspace_mariadb_password | to_json }}, "database": {{ app_db_name | to_json }}, "charset": "utf8mb4" }, "requireAuthentication": true, "showSettingsInAdminPage": false, "users": { {{ app_admin_username | to_json }}: { "password": {{ lookup('ansible.builtin.password', '/dev/null length=32 chars=ascii_letters,digits') | to_json }}, "is_admin": true } }, "updates": {"tier": "off"} } no_log: true - name: Create the systemd directory file: path: "{{ _home }}/.config/systemd/user" state: directory mode: '0700' - name: Create the Etherpad service copy: dest: "{{ _home }}/.config/systemd/user/etherpad.service" mode: '0644' content: | [Unit] Description=Etherpad [Service] WorkingDirectory=%h/opt/etherpad ExecStart=/usr/bin/pnpm run prod Environment=NODE_ENV=production Restart=on-failure RestartSec=5 UMask=0077 [Install] WantedBy=default.target - name: Enable and start Etherpad systemd: name: etherpad scope: user daemon_reload: true enabled: true state: started - name: Wait for Etherpad to require login uri: url: "http://127.0.0.1:{{ app_port }}/" status_code: 401 register: health until: health.status == 401 retries: 24 delay: 5 - name: Register the domain command: argv: [uberspace, web, domain, add, "{{ app_domain }}", --wait] when: app_domain not in (domains.stdout | from_json | map(attribute='name') | list) - name: Route the domain to Etherpad command: argv: [uberspace, web, backend, add, "{{ app_domain }}/", port, "{{ app_port | string }}", --force, --wait] - name: Verify the public login requirement uri: url: "https://{{ app_domain }}/" status_code: 401 register: site until: site.status == 401 retries: 12 delay: 5 - name: _Report debug: msg: | Etherpad: https://{{ app_domain }} Installed version: {{ release.json.tag_name }} Username: {{ app_admin_username }} Read the generated password in ~/opt/etherpad/settings.json over SSH. Updates are manual. Back up files and MariaDB before updating. Guide: https://u8lab.uberspace.de/guide_etherpad-lite/