From 87bf91d655d8feed0b92e3bd5b45c17942818496 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Thu, 18 Jun 2026 12:47:41 +0000 Subject: [PATCH] fix(macos): use native PostgreSQL mode on Darwin (Linux keeps compose) postgresql_deploy_mode defaults to compose (Docker) and the admin password is generated via a /root password-file lookup, both of which fail on a native macOS deploy (no Docker, /root not writable). The role already ships a native path (macos.yml, Homebrew postgresql@16). In the script's Darwin block, set postgresql_deploy_mode=native and pass postgresql_admin_password directly (highest-precedence extra-var, bypassing the /root lookup). Linux unchanged. Documents TC-MAC-017. --- docs/case/macos_compatibility_tests.md | 10 ++++++++++ docs/report/TC-MAC-012-26-06-18-19.md | 14 ++++++++++++++ scripts/setup-ai-workspace-all-in-one.sh | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/docs/case/macos_compatibility_tests.md b/docs/case/macos_compatibility_tests.md index 2a0c377..be20169 100644 --- a/docs/case/macos_compatibility_tests.md +++ b/docs/case/macos_compatibility_tests.md @@ -147,6 +147,16 @@ | **修复方案** | 不再依赖会被 MFA 拦截的登录:改为通过 userpass 的 identity **entity-alias** 解析 `entity_id`——遍历 `identity/entity-alias/id` 找到 name==用户、mount_accessor==userpass accessor 的别名取其 `canonical_id`;首次运行(无别名)则显式创建 entity + entity-alias。移除随之不再需要的 `vault token revoke`。幂等、向后兼容(能识别旧版本登录隐式创建的 entity)。已在真实 playbooks 仓库 `init_vault_admin.sh` 修复;clone 路径由 `patch_playbook_vault_macos()` 同步打补丁 | | **定位手段** | 该任务 `no_log: true` 隐藏了错误;临时改 `no_log: false` + register + 将 stdout/stderr 写入挂载目录文件,直接读取得到真实报错 | +## TC-MAC-017: PostgreSQL 在 macOS 误用 compose 模式 + +| 项目 | 内容 | +|------|------| +| **触发文件** | `roles/vhosts/postgres/tasks/compose.yml`、`roles/vhosts/postgres/defaults/main.yml` | +| **触发报错** | `TASK [postgres : Materialize PostgreSQL admin password]` 失败(`no_log: true`)。assert `postgresql_admin_password | length > 0` 为空 | +| **根因** | `postgresql_deploy_mode` 默认 `compose`。compose.yml 走 Docker 路径(检查/安装 apt 版 docker),且 `postgresql_admin_password` 默认经 `lookup('password', '/root/.ai_workspace_postgres_password ...')` 生成——macOS 无权写 `/root`,lookup 失败 → 密码为空 → assert 失败。该角色其实已备 `native`+`macos.yml`(Homebrew postgresql@16)路径,但默认未在 macOS 切换过去 | +| **目录/模式策略** | macOS 部署 `postgresql_deploy_mode=native`(→ `macos.yml`,brew 安装);Linux 部署保持默认 `compose` | +| **修复方案** | 在 `setup-ai-workspace-all-in-one.sh` 的 Darwin 分支注入 `-e postgresql_deploy_mode=native`,并以 `append_secret_var postgresql_admin_password=$UNIFIED_AUTH_TOKEN` 直接提供密码(extra-vars 优先级最高,彻底绕过 `/root` 的 password lookup)。Linux 分支不变 | + --- ## 修复维度总结 diff --git a/docs/report/TC-MAC-012-26-06-18-19.md b/docs/report/TC-MAC-012-26-06-18-19.md index f50c75e..94e3ffb 100644 --- a/docs/report/TC-MAC-012-26-06-18-19.md +++ b/docs/report/TC-MAC-012-26-06-18-19.md @@ -173,3 +173,17 @@ PUT /v1/identity/mfa/method/totp/admin-generate **运行建议**:用真实仓库作为来源最干净: `PLAYBOOK_DIR=/Users/shenlan/workspaces/cloud-neutral-toolkit/playbooks bash scripts/setup-ai-workspace-all-in-one.sh` (或把两仓库 push 到各自 main 后再 `curl | bash`)。 + +--- + +## 12. 续:PostgreSQL 模式选择(TC-MAC-017,20:43) + +**进展**:vault bootstrap 已通过(出现在耗时榜,不再失败)。新阻塞点 `postgres : Materialize PostgreSQL admin password`。 + +**根因**:`postgresql_deploy_mode` 默认 `compose`(Docker 路径),macOS 不适用;且密码默认经 `/root/.ai_workspace_postgres_password` 的 password lookup 生成,macOS 无权写 `/root` → 密码空 → assert 失败。角色其实已备 `native`+`macos.yml`(brew postgresql@16)。 + +**策略(按用户确认)**:macOS → `native`;Linux → 默认 `compose`。 + +**修复**:脚本 Darwin 分支注入 `-e postgresql_deploy_mode=native` + `append_secret_var postgresql_admin_password=$UNIFIED_AUTH_TOKEN`(直接给密码,绕过 `/root` lookup)。纯脚本改动,Linux 不变。`bash -n` 通过,`append_secret_var` 在用前已定义。 + +**后续观察**:native 路径 `macos.yml` 使用 `community.general.homebrew` 模块,若该 collection 未安装可能是下一个点;先验证本步。 diff --git a/scripts/setup-ai-workspace-all-in-one.sh b/scripts/setup-ai-workspace-all-in-one.sh index 5930773..256125b 100755 --- a/scripts/setup-ai-workspace-all-in-one.sh +++ b/scripts/setup-ai-workspace-all-in-one.sh @@ -2202,6 +2202,13 @@ if [ "$(detect_os)" = "darwin" ]; then # is both non-writable under become=false and non-standard for the platform. # Relocate it to the Apple-standard per-user app data location instead. ANSIBLE_EXTRA_VARS+=("-e" "xworkmate_bridge_base_dir=$HOME/Library/Application Support/cloud-neutral/xworkmate-bridge") + # PostgreSQL defaults to compose (Docker) mode, which is inappropriate on a + # native macOS deploy: it pulls in the apt-based docker role and stores the + # admin password under /root. Use native mode (Homebrew postgresql@16 via the + # role's macos.yml) and pass the admin password directly so the default + # /root/.ai_workspace_postgres_password lookup is never attempted. + ANSIBLE_EXTRA_VARS+=("-e" "postgresql_deploy_mode=native") + append_secret_var "postgresql_admin_password" "$UNIFIED_AUTH_TOKEN" else LINUX_CONSOLE_USER="$(linux_default_console_user)" LINUX_CONSOLE_HOME="$(linux_default_console_home "$LINUX_CONSOLE_USER")"