Skip to content

Commit 8bd946c

Browse files
mrveissclaude
andcommitted
feat(ansible): add sync-code-source.yml to push code from controller to SLM (#3604)
Adds a new playbook that rsync's the dev machine's local checkout to /opt/autobot/code_source on the SLM manager. Integrated into deploy-slm-manager.yml as a no-op step when controller_repo_root is not set, and active when passed via -e: ansible-playbook ... -e "controller_repo_root=/path/to/AutoBot-AI" Closes the offline-deployment gap where the pre-flight GitHub pull silently falls back to stale code_source, causing fixes that exist in the local repo to never reach the SLM. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b60c41c commit 8bd946c

File tree

2 files changed

+102
-10
lines changed

2 files changed

+102
-10
lines changed

autobot-slm-backend/ansible/playbooks/deploy-slm-manager.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
# ansible-playbook -i inventory/slm-nodes.yml playbooks/deploy-slm-manager.yml
1414
#
1515
# Tags:
16-
# --tags packages System packages only
17-
# --tags tls TLS certificate generation only
18-
# --tags backend Backend venv + service only
19-
# --tags frontend Frontend build only
20-
# --tags nginx Nginx config only
21-
# --tags service Start/restart services only
22-
# --tags postgresql Database only
23-
# --tags monitoring Prometheus + Grafana only
24-
# --tags seed Register fleet nodes in SLM database
25-
# --tags provision Auto-provision fleet nodes by role
16+
# --tags packages System packages only
17+
# --tags tls TLS certificate generation only
18+
# --tags backend Backend venv + service only
19+
# --tags frontend Frontend build only
20+
# --tags nginx Nginx config only
21+
# --tags service Start/restart services only
22+
# --tags postgresql Database only
23+
# --tags monitoring Prometheus + Grafana only
24+
# --tags seed Register fleet nodes in SLM database
25+
# --tags provision Auto-provision fleet nodes by role
26+
# --tags code-source Push code_source from controller only
27+
#
28+
# When GitHub is unreachable from SLM, pass controller_repo_root to push
29+
# the local checkout to SLM before provisioning (#3604):
30+
# ansible-playbook ... -e "controller_repo_root=/home/martins/AutoBot-Ai/AutoBot-AI"
2631
---
2732
- name: Deploy SLM Manager
2833
hosts: 00-SLM-Manager
@@ -58,6 +63,12 @@
5863
monitoring_install_grafana: true
5964
monitoring_install_node_exporter: true
6065

66+
# Push code_source from controller to SLM before provisioning (#3604).
67+
# No-op when controller_repo_root is not set (e.g. triggered from SLM web UI).
68+
- name: Sync code_source from controller
69+
import_playbook: sync-code-source.yml
70+
tags: ['code-source', 'provision']
71+
6172
# After all services are up, register fleet nodes in SLM database
6273
- name: Seed Fleet Nodes
6374
import_playbook: seed-fleet-nodes.yml
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# AutoBot - AI-Powered Automation Platform
2+
# Copyright (c) 2025 mrveiss
3+
# Author: mrveiss
4+
#
5+
# Push code_source from the Ansible controller to the SLM manager (#3604)
6+
#
7+
# When GitHub is unreachable FROM the SLM manager, the pre-flight git pull
8+
# in provision-fleet-roles.yml silently falls back to whatever is already
9+
# in /opt/autobot/code_source. This playbook closes that gap: run it from
10+
# the dev machine BEFORE provisioning to push the current local checkout to
11+
# SLM, so roles, templates, and playbooks are always up-to-date regardless
12+
# of whether the SLM can reach GitHub.
13+
#
14+
# Usage (from dev machine):
15+
# ansible-playbook -i inventory/hosts.yml playbooks/sync-code-source.yml \
16+
# -e "controller_repo_root=/home/martins/AutoBot-Ai/AutoBot-AI"
17+
#
18+
# When imported by deploy-slm-manager.yml the variable is set automatically
19+
# via the playbook vars block at the top of that file.
20+
#
21+
# When controller_repo_root is not defined this play is a no-op, so it is
22+
# safe to always import from deploy-slm-manager.yml without a guard.
23+
---
24+
- name: "Sync code_source: push from controller to SLM"
25+
hosts: 00-SLM-Manager
26+
become: true
27+
gather_facts: false
28+
29+
vars:
30+
_code_source_dest: "{{ code_source_dir | default('/opt/autobot/code_source') }}"
31+
_code_source_owner: "{{ code_source_owner | default('root') }}"
32+
_code_source_group: "{{ code_source_group | default('root') }}"
33+
34+
tasks:
35+
- name: "code_source sync | Skip when controller_repo_root not set"
36+
ansible.builtin.debug:
37+
msg: >-
38+
controller_repo_root not defined — skipping local push.
39+
Set -e "controller_repo_root=/path/to/AutoBot-AI" to push from
40+
the dev machine before provisioning.
41+
when: controller_repo_root is not defined
42+
tags: ['code-source', 'sync']
43+
44+
- name: "code_source sync | Push {{ controller_repo_root }} → {{ _code_source_dest }}"
45+
ansible.posix.synchronize:
46+
src: "{{ controller_repo_root }}/"
47+
dest: "{{ _code_source_dest }}/"
48+
rsync_opts:
49+
- "--exclude=.git"
50+
- "--exclude=*.pyc"
51+
- "--exclude=__pycache__"
52+
- "--exclude=node_modules"
53+
- "--exclude=dist"
54+
- "--exclude=.worktrees"
55+
- "--delete"
56+
when: controller_repo_root is defined
57+
tags: ['code-source', 'sync']
58+
59+
- name: "code_source sync | Fix ownership on {{ _code_source_dest }}"
60+
ansible.builtin.file:
61+
path: "{{ _code_source_dest }}"
62+
state: directory
63+
owner: "{{ _code_source_owner }}"
64+
group: "{{ _code_source_group }}"
65+
recurse: true
66+
when: controller_repo_root is defined
67+
tags: ['code-source', 'sync']
68+
69+
- name: "code_source sync | Show pushed commit"
70+
ansible.builtin.command:
71+
cmd: "git -C {{ _code_source_dest }} log -1 --format='%h %s'"
72+
register: _pushed_commit
73+
changed_when: false
74+
when: controller_repo_root is defined
75+
tags: ['code-source', 'sync']
76+
77+
- name: "code_source sync | Report result"
78+
ansible.builtin.debug:
79+
msg: "code_source now at: {{ _pushed_commit.stdout }}"
80+
when: controller_repo_root is defined
81+
tags: ['code-source', 'sync']

0 commit comments

Comments
 (0)