|
308 | 308 | # checking for the user frontend package.json, but it runs before |
309 | 309 | # the frontend role syncs the code. This phase re-renders the |
310 | 310 | # 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). |
311 | 315 | # ------------------------------------------------------------------- |
312 | 316 | - name: "Provision Phase 4c: SLM Nginx Co-location Update" |
313 | 317 | hosts: all |
314 | 318 | become: true |
315 | 319 | gather_facts: false |
316 | 320 |
|
317 | 321 | 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 |
332 | 328 | tags: ['frontend', 'slm-nginx', 'provision'] |
333 | 329 |
|
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" |
335 | 331 | ansible.builtin.stat: |
336 | 332 | path: "{{ frontend_dist_dir | default('/opt/autobot/autobot-frontend/dist') | dirname }}/package.json" |
337 | 333 | register: _post_frontend_colocated_check |
338 | | - when: _is_slm_manager | bool |
| 334 | + when: _slm_nginx_config_stat.stat.exists |
339 | 335 | tags: ['frontend', 'slm-nginx', 'provision'] |
340 | 336 |
|
341 | | - - name: "SLM | Resolve co-location flag (wizard var or package.json fallback)" |
| 337 | + - name: "SLM | Resolve co-location flag" |
342 | 338 | ansible.builtin.set_fact: |
343 | 339 | _is_slm_frontend_colocated: >- |
344 | 340 | {{ |
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 |
349 | 343 | }} |
350 | | - when: _is_slm_manager | bool |
351 | 344 | tags: ['frontend', 'slm-nginx', 'provision'] |
352 | 345 |
|
353 | 346 | - name: "SLM | Load slm_manager defaults for nginx re-render" |
354 | 347 | ansible.builtin.include_vars: |
355 | 348 | 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 |
357 | 350 | tags: ['frontend', 'slm-nginx', 'provision'] |
358 | 351 |
|
359 | 352 | - name: "SLM | Re-render SLM nginx config for co-located mode (#3012)" |
360 | 353 | 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" |
362 | 355 | dest: "/etc/nginx/sites-available/{{ slm_nginx_config | default('autobot-slm') }}" |
363 | 356 | mode: "0644" |
364 | 357 | backup: true |
365 | 358 | vars: |
366 | 359 | slm_colocated_frontend: true |
367 | | - when: _is_slm_frontend_colocated | default(false) | bool |
| 360 | + when: _is_slm_frontend_colocated | bool |
368 | 361 | register: _slm_nginx_rerendered |
369 | 362 | tags: ['frontend', 'slm-nginx', 'provision'] |
370 | 363 |
|
|
379 | 372 | become_user: "{{ slm_user | default('autobot') }}" |
380 | 373 | environment: |
381 | 374 | VITE_API_URL: "/slm" |
382 | | - when: _is_slm_frontend_colocated | default(false) | bool |
| 375 | + when: _is_slm_frontend_colocated | bool |
383 | 376 | changed_when: true |
384 | 377 | tags: ['frontend', 'slm-nginx', 'provision'] |
385 | 378 |
|
|
0 commit comments