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 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-11 08:33:41 -07:00
1 parent cccdca1469
commit 310e5523f1
3 files changed
+33 -23

No files matched your search

+27 -19
View File
@@ -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]