Skip to content

Commit f0ab7a7

Browse files
mrveissclaude
andcommitted
fix(ansible): replace fragile group-based SLM detection in Phase 4c with filesystem stat
The _is_slm_manager check relied on inventory group membership (slm_server/slm) or node_roles values, both of which are absent in temp inventories generated by per-node provisioning from the SLM UI. This caused Phase 4c to skip the nginx co-location re-render entirely, leaving / → /slm/ redirect intact even when the user frontend was deployed on the same host. Replace with filesystem-based detection: 1. Stat /etc/nginx/sites-available/autobot-slm to identify the SLM manager 2. Stat autobot-frontend/package.json to confirm co-location Both stats work regardless of inventory shape (wizard, per-node, static). Also remove the role_path fallback in the template src — the playbook_dir relative path is always correct and avoids a None-based string. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8bd946c commit f0ab7a7

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

autobot-slm-backend/ansible/playbooks/provision-fleet-roles.yml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -308,63 +308,56 @@
308308
# checking for the user frontend package.json, but it runs before
309309
# the frontend role syncs the code. This phase re-renders the
310310
# SLM nginx config after the frontend role has completed.
311+
#
312+
# Detection is purely filesystem-based so it works regardless of
313+
# whether provisioning was triggered via the setup wizard (full
314+
# fleet inventory) or per-node API (temp inventory with no groups).
311315
# -------------------------------------------------------------------
312316
- name: "Provision Phase 4c: SLM Nginx Co-location Update"
313317
hosts: all
314318
become: true
315319
gather_facts: false
316320

317321
tasks:
318-
# Detect co-location on the SLM manager host (#3426):
319-
# 1. Wizard sets slm_colocated_frontend=True on 00-SLM-Manager when any
320-
# local node carries the 'frontend' role.
321-
# 2. Standalone runs (slm-nodes.yml) fall back to the package.json stat.
322-
# Only runs on slm_server/slm group hosts; skipped on all others.
323-
- name: "SLM | Determine if this is the SLM manager host"
324-
ansible.builtin.set_fact:
325-
_is_slm_manager: >-
326-
{{
327-
inventory_hostname in groups.get('slm_server', []) or
328-
inventory_hostname in groups.get('slm', []) or
329-
'slm-backend' in (node_roles | default([])) or
330-
'slm_manager' in (node_roles | default([]))
331-
}}
322+
# Use filesystem state rather than inventory group membership so
323+
# this works with any inventory shape (wizard, per-node, static).
324+
- name: "SLM | Stat SLM nginx config to detect SLM manager host"
325+
ansible.builtin.stat:
326+
path: "/etc/nginx/sites-available/{{ slm_nginx_config | default('autobot-slm') }}"
327+
register: _slm_nginx_config_stat
332328
tags: ['frontend', 'slm-nginx', 'provision']
333329

334-
- name: "SLM | Stat user frontend package.json for fallback co-location detection"
330+
- name: "SLM | Stat user frontend package.json for co-location detection"
335331
ansible.builtin.stat:
336332
path: "{{ frontend_dist_dir | default('/opt/autobot/autobot-frontend/dist') | dirname }}/package.json"
337333
register: _post_frontend_colocated_check
338-
when: _is_slm_manager | bool
334+
when: _slm_nginx_config_stat.stat.exists
339335
tags: ['frontend', 'slm-nginx', 'provision']
340336

341-
- name: "SLM | Resolve co-location flag (wizard var or package.json fallback)"
337+
- name: "SLM | Resolve co-location flag"
342338
ansible.builtin.set_fact:
343339
_is_slm_frontend_colocated: >-
344340
{{
345-
_is_slm_manager | bool and (
346-
slm_colocated_frontend | default(false) | bool or
347-
_post_frontend_colocated_check.stat.exists | default(false) | bool
348-
)
341+
_slm_nginx_config_stat.stat.exists and
342+
_post_frontend_colocated_check.stat.exists | default(false) | bool
349343
}}
350-
when: _is_slm_manager | bool
351344
tags: ['frontend', 'slm-nginx', 'provision']
352345

353346
- name: "SLM | Load slm_manager defaults for nginx re-render"
354347
ansible.builtin.include_vars:
355348
file: "{{ playbook_dir }}/../roles/slm_manager/defaults/main.yml"
356-
when: _is_slm_frontend_colocated | default(false) | bool
349+
when: _is_slm_frontend_colocated | bool
357350
tags: ['frontend', 'slm-nginx', 'provision']
358351

359352
- name: "SLM | Re-render SLM nginx config for co-located mode (#3012)"
360353
ansible.builtin.template:
361-
src: "{{ role_path | default(playbook_dir + '/../roles/slm_manager') }}/templates/autobot-slm.conf.j2"
354+
src: "{{ playbook_dir }}/../roles/slm_manager/templates/autobot-slm.conf.j2"
362355
dest: "/etc/nginx/sites-available/{{ slm_nginx_config | default('autobot-slm') }}"
363356
mode: "0644"
364357
backup: true
365358
vars:
366359
slm_colocated_frontend: true
367-
when: _is_slm_frontend_colocated | default(false) | bool
360+
when: _is_slm_frontend_colocated | bool
368361
register: _slm_nginx_rerendered
369362
tags: ['frontend', 'slm-nginx', 'provision']
370363

@@ -379,7 +372,7 @@
379372
become_user: "{{ slm_user | default('autobot') }}"
380373
environment:
381374
VITE_API_URL: "/slm"
382-
when: _is_slm_frontend_colocated | default(false) | bool
375+
when: _is_slm_frontend_colocated | bool
383376
changed_when: true
384377
tags: ['frontend', 'slm-nginx', 'provision']
385378

0 commit comments

Comments
 (0)