- hosts: localhost vars: meta: application_name: Tachyon playbook_version: 0.1 app_domain: "{{ uberspace_default_web_domain }}" app_mail_domain: "{{ uberspace_default_web_domain }}" app_mail_server: "{{ ansible_facts['fqdn'] }}" _home: "/home/{{ uberspace_asteroid_name }}" _root: "/var/www/virtual/{{ uberspace_asteroid_name }}/tachyon" 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_mail_domain is match('^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$') - app_domain is match('^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$') fail_msg: "Use a valid domain." - name: Inspect installation and service paths stat: path: "{{ item }}" loop: - "{{ _root }}" - "{{ _home }}/tachyon-data" 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: 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: List registered web domains command: argv: [uberspace, web, domain, list, --json] register: domains changed_when: false check_mode: false - name: Install Tachyon when: not ansible_check_mode block: - name: Find the latest stable release uri: url: https://api.github.com/repos/kimusan/Tachyon/releases/latest return_content: true register: release - name: Select the bundled archive set_fact: _asset: "{{ (release.json.assets | selectattr('name', 'equalto', 'tachyon-latest.tar.gz') | first) }}" - name: Require a published SHA256 digest assert: that: _asset.digest is match('^sha256:[a-f0-9]{64}$') - name: Select PHP 8.4 command: argv: [uberspace, tool, php, version, set, '8.4'] - name: Create the application directory file: path: "{{ _root }}" state: directory mode: '0755' - name: Download and verify the release get_url: url: "{{ _asset.browser_download_url }}" dest: "{{ _home }}/tachyon-release.tar.gz" checksum: "{{ _asset.digest }}" mode: '0600' - name: Extract the release unarchive: src: "{{ _home }}/tachyon-release.tar.gz" dest: "{{ _root }}" remote_src: true - name: Move private data outside the document root command: argv: [mv, "{{ _root }}/data", "{{ _home }}/tachyon-data"] - name: Protect the private data directory file: path: "{{ _home }}/tachyon-data" state: directory mode: '0700' - name: Configure the private data path copy: dest: "{{ _root }}/include.php" mode: '0600' content: | SetPassword(new \Tachyon\Util\SensitiveString($password)); if (!$config->Save()) { throw new RuntimeException('Cannot save configuration'); } file_put_contents('{{ _home }}/tachyon-admin-password', $password . "\n"); chmod('{{ _home }}/tachyon-admin-password', 0600); $domain = new \Tachyon\Model\Domain({{ app_mail_domain | to_json }}); $domain->ImapSettings()->host = {{ app_mail_server | to_json }}; $domain->ImapSettings()->port = 993; $domain->ImapSettings()->type = 1; $domain->ImapSettings()->shortLogin = false; $domain->SmtpSettings()->host = {{ app_mail_server | to_json }}; $domain->SmtpSettings()->port = 587; $domain->SmtpSettings()->type = 2; $domain->SmtpSettings()->shortLogin = false; $domain->SmtpSettings()->useAuth = true; $domain->SieveSettings()->enabled = true; $domain->SieveSettings()->host = {{ app_mail_server | to_json }}; $domain->SieveSettings()->port = 4190; $domain->SieveSettings()->type = 2; foreach (glob(APP_PRIVATE_DATA . 'domains/*.json') as $file) { unlink($file); } $provider = new \Tachyon\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA . 'domains'); if (!$provider->Save($domain)) { throw new RuntimeException('Cannot save domain'); } - name: _Initialize the administrator and mail domain command: argv: [php, "{{ _home }}/tachyon-setup.php"] no_log: true - name: Remove the setup script file: path: "{{ _home }}/tachyon-setup.php" state: absent - name: Remove the empty default document root file: path: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" state: absent - name: Publish the application through the standard document root file: src: "{{ _root }}" dest: "/var/www/virtual/{{ uberspace_asteroid_name }}/html" state: link - 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 Apache command: argv: [uberspace, web, backend, add, "{{ app_domain }}/", apache, --force, --wait] - name: Check public availability uri: url: "https://{{ app_domain }}/" register: health until: health.status == 200 retries: 12 delay: 5 - name: _Report debug: msg: "Tachyon is ready at https://{{ app_domain }}/. Administrator login: https://{{ app_domain }}/?admin, username admin, password stored privately in ~/tachyon-admin-password. Mail users log in with their existing full mailbox address and mailbox password."