# Hermes never installs a service for its dashboard; this is the launchd # version of the systemd unit in its docs (user-guide/features/web-dashboard). # Login: username + scrypt password hash + a fixed signing secret, so sessions # survive restarts. public_url makes it accept the Tailscale Serve origin. - name: Dashboard login and public URL in Hermes's .env ansible.builtin.lineinfile: path: "{{ hermes_env }}" regexp: "^{{ item.key }}=" # Single quotes: Hermes reads .env without interpolation, and the hash has $ in it. line: "{{ item.key }}='{{ item.value }}'" mode: "0600" loop: - { key: HERMES_DASHBOARD_BASIC_AUTH_USERNAME, value: "{{ hermes_dashboard_username }}" } - { key: HERMES_DASHBOARD_BASIC_AUTH_PASSWORD_HASH, value: "{{ vault_cogitator02.dashboard_password_hash }}" } - { key: HERMES_DASHBOARD_BASIC_AUTH_SECRET, value: "{{ vault_cogitator02.dashboard_secret }}" } - { key: HERMES_DASHBOARD_PUBLIC_URL, value: "{{ hermes_dashboard_url }}" } no_log: true diff: false notify: Restart Hermes dashboard # A plaintext password overrides the hash, so it must not be there. - name: No plaintext dashboard password in .env ansible.builtin.lineinfile: path: "{{ hermes_env }}" regexp: "^HERMES_DASHBOARD_BASIC_AUTH_PASSWORD=" state: absent no_log: true diff: false notify: Restart Hermes dashboard - name: Dashboard launchd service ansible.builtin.template: src: hermes-dashboard.plist.j2 dest: "{{ ansible_user_dir }}/Library/LaunchAgents/{{ hermes_dashboard_label }}.plist" mode: "0644" register: dashboard_plist notify: Restart Hermes dashboard - name: Dashboard running community.general.launchd: name: "{{ hermes_dashboard_label }}" state: started # In a dry run of the first deploy the plist doesn't exist yet. when: not (ansible_check_mode and dashboard_plist is changed) # Restart now on changes, so the login check below tests the new settings. - name: Apply dashboard changes ansible.builtin.meta: flush_handlers # Tailscale Serve: tailnet-only HTTPS on https://.ts.net, proxied to # the loopback dashboard. No Ansible module manages it, so read the current # config and set it only when it differs. --bg keeps it across reboots. # TAILSCALE_BE_CLI makes the app binary act as the CLI without a terminal. - name: Read Tailscale Serve config ansible.builtin.command: argv: ["{{ tailscale_cli }}", serve, status, --json] environment: TAILSCALE_BE_CLI: "1" register: tailscale_serve changed_when: false check_mode: false - name: Serve the dashboard on the tailnet over HTTPS ansible.builtin.command: argv: ["{{ tailscale_cli }}", serve, --bg, --https=443, "http://127.0.0.1:{{ hermes_dashboard_port }}"] environment: TAILSCALE_BE_CLI: "1" when: >- (tailscale_serve.stdout | from_json).get('Web', {}).get(ansible_host ~ ':443', {}) .get('Handlers', {}).get('/', {}).get('Proxy', '') != 'http://127.0.0.1:' ~ hermes_dashboard_port # The dashboard must ask for a login through Serve. If it doesn't, take it # off the tailnet and stop. - name: Check the dashboard login is on when: not ansible_check_mode block: - name: Wait for the dashboard to answer through Tailscale Serve ansible.builtin.uri: url: "{{ hermes_dashboard_url }}/api/status" return_content: true register: dashboard_status until: dashboard_status.status == 200 retries: 12 delay: 5 - name: Dashboard requires the username/password login ansible.builtin.assert: that: - dashboard_status.json.auth_required | bool - "'basic' in dashboard_status.json.auth_providers" quiet: true rescue: - name: Take the dashboard off the tailnet ansible.builtin.command: argv: ["{{ tailscale_cli }}", serve, --https=443, "off"] environment: TAILSCALE_BE_CLI: "1" - name: Stop here ansible.builtin.fail: msg: >- The dashboard didn't answer or doesn't require a login through {{ hermes_dashboard_url }}, so Tailscale Serve was turned off. Check ~/.hermes/logs/dashboard.error.log on the Mac.