From 310e5523f1a78313e96bd114728c807d2a289225 Mon Sep 17 00:00:00 2001 From: Phil Date: Wed, 11 Nov 2026 08:33:41 -0700 Subject: [PATCH] Mac: compare Hermes settings against config.yaml; restart with --yes `hermes config get` fills in and masks ${VAR} references, so the Karakeep MCP entry (env KARAKEEP_API_KEY: ${KARAKEEP_API_KEY}) never matched and every deploy re-set it and restarted the gateway. It also prints defaults for unset keys and exits 1 for keys without one. Compare against ~/.hermes/config.yaml itself instead. `hermes gateway restart` without a terminal refuses while anything is running unless given --yes (docs, reference/cli-commands); the failed handler left the gateway restarting under launchd but the play failed. Co-Authored-By: Claude Opus 5.5 --- roles/mac/README.md | 4 +-- roles/mac/handlers/main.yml | 6 ++-- roles/mac/tasks/hermes-settings.yml | 46 +++++++++++++++++------------ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/roles/mac/README.md b/roles/mac/README.md index ab8d39a..3126790 100644 --- a/roles/mac/README.md +++ b/roles/mac/README.md @@ -23,8 +23,8 @@ Manages cogitator-02, an Apple Silicon Mac on the tailnet (`mac.yml`, override the hash). After setting up Serve, the play checks the dashboard demands a login through it; if not, it turns Serve off and fails. - **Hermes settings** (tag `hermes-settings`): the individual keys in - `hermes_settings` (`group_vars/mac/main.yml`), checked with - `hermes config get` and fixed with `hermes config set`; any change restarts the gateway (`hermes gateway restart`) + `hermes_settings` (`group_vars/mac/main.yml`), compared against + `~/.hermes/config.yaml` and fixed with `hermes config set`; any change restarts the gateway (`hermes gateway restart`) and the dashboard. Covers update backups, timezone, not borrowing Claude Code's login, sandbox memory, disabled toolsets, skill-write approval, deny rules, streaming, diff --git a/roles/mac/handlers/main.yml b/roles/mac/handlers/main.yml index 9dd9e22..087d275 100644 --- a/roles/mac/handlers/main.yml +++ b/roles/mac/handlers/main.yml @@ -5,8 +5,10 @@ # Nothing to restart in a dry run (on the first deploy the plist isn't there). when: not ansible_check_mode -# Lets running turns finish first (unlike launchctl kickstart -k). +# Lets running turns finish first (unlike launchctl kickstart -k). Without a +# terminal it refuses while turns, cron jobs or subagents are running unless +# given --yes; the gateway then exits 75 and launchd starts a new one. - name: Restart Hermes gateway ansible.builtin.command: - argv: ["{{ hermes_cli }}", gateway, restart] + argv: ["{{ hermes_cli }}", gateway, restart, --yes] when: not ansible_check_mode diff --git a/roles/mac/tasks/hermes-settings.yml b/roles/mac/tasks/hermes-settings.yml index 711574c..9af0a26 100644 --- a/roles/mac/tasks/hermes-settings.yml +++ b/roles/mac/tasks/hermes-settings.yml @@ -11,30 +11,38 @@ diff: false notify: [Restart Hermes gateway, Restart Hermes dashboard] -# `hermes config get` prints the value as YAML, so it's compared -# structurally; `hermes config set` takes JSON for lists and booleans. -# Settings are always set explicitly: for a key that isn't in config.yaml, -# `config get` (non-interactive) prints just the default when there is one, -# so "unset" can't be detected. -- name: Read Hermes settings - ansible.builtin.command: - argv: ["{{ hermes_cli }}", config, get, "{{ item.key }}"] - loop: "{{ hermes_settings | dict2items }}" - register: hermes_settings_current - changed_when: false - # Exit 1 = "Config key not set" (only for keys without a built-in default). - failed_when: hermes_settings_current.rc > 1 - check_mode: false +# Compared against ~/.hermes/config.yaml itself: `hermes config get` prints +# defaults for unset keys, exits 1 for keys without a default, and fills in +# and masks ${VAR} references, so it can't tell what's actually set. +- name: Read Hermes's config.yaml + ansible.builtin.slurp: + src: "{{ ansible_user_dir }}/.hermes/config.yaml" + register: hermes_config_file +- name: Note the current value of each setting + ansible.builtin.set_fact: + hermes_settings_current: >- + {%- set config = hermes_config_file.content | b64decode | from_yaml -%} + {%- set current = {} -%} + {%- for key in hermes_settings -%} + {%- set node = namespace(value=config) -%} + {%- for part in key.split('.') -%} + {%- set node.value = node.value[part] if (node.value is mapping and part in node.value) else none -%} + {%- endfor -%} + {%- set _ = current.update({key: node.value}) -%} + {%- endfor -%} + {{ current }} + +# `hermes config set` takes JSON for lists, mappings and booleans. - name: Set Hermes settings ansible.builtin.command: argv: >- {{ [hermes_cli, 'config', 'set'] - + (['--force'] if item.item.key in hermes_settings_force | default([]) else []) - + [item.item.key, item.item.value if item.item.value is string else item.item.value | to_json] }} - loop: "{{ hermes_settings_current.results }}" + + (['--force'] if item.key in hermes_settings_force | default([]) else []) + + [item.key, item.value if item.value is string else item.value | to_json] }} + loop: "{{ hermes_settings | dict2items }}" loop_control: - label: "{{ item.item.key }} = {{ item.item.value | to_json }}" - when: (none if item.rc == 1 else item.stdout | from_yaml) != item.item.value + label: "{{ item.key }} = {{ item.value | to_json }}" + when: hermes_settings_current[item.key] != item.value # The dashboard is a separate process with its own copy of the settings. notify: [Restart Hermes gateway, Restart Hermes dashboard]