Provisioning fixes: auth-based readiness, domain join guards, site push

- wait for WinRM with an authenticated call, not a TCP probe: the port opens
  before the service can authenticate
- skip promotion/join when the machine is already there, so provision is
  idempotent
- probe the domain with System.DirectoryServices: Get-ADDomain needs RSAT,
  which a member server does not have
- passwords must not contain the account name (Legault2024! is rejected)
- Web-Dir-Browsing is the real feature name
- push the site over SMB from C$: WinRM caps the command line at 8 KB
This commit is contained in:
2026-10-21 20:02:43 -04:00
parent bb8a6a6eb0
commit 645adea875
9 changed files with 83 additions and 34 deletions
+13 -6
View File
@@ -12,20 +12,21 @@ _winrm() {
# A guest that is installing features or restarting WinRM answers intermittently.
_winrm_retry() {
local n=1
while (( n <= 5 )); do
while (( n <= 10 )); do
if _winrm "$@"; then return 0; fi
warn "winrm attempt ${n}/5 failed, retrying"
warn "winrm attempt ${n}/10 failed, retrying"
sleep 15
n=$(( n + 1 ))
done
return 1
}
# The TCP port opens before WinRM can authenticate, so probe with a real call.
_wait_winrm() {
local host=$1 timeout=${2:-1800}
local deadline=$(( SECONDS + timeout ))
while (( SECONDS < deadline )); do
if tcp_open "$host" 5985; then
if _winrm "$host" ps 'exit 0' >/dev/null 2>&1; then
return 0
fi
sleep 10
@@ -82,12 +83,18 @@ _provision_one() {
ok "$name: $marker"
# A reboot stage drops WinRM; wait for the guest to come back before post.
if [[ $marker == *reboot* ]] || [[ -f $post ]]; then
if [[ -f $post ]]; then
info " waiting for the guest to come back"
_wait_winrm "$ip" 900 || { fail "$name: did not come back after reboot"; return 1; }
fi
if [[ -f $post ]]; then
# Clear a marker from an earlier attempt, then run the stage ourselves —
# an ONSTART task has already fired by the time we get here.
_winrm_retry "$ip" ps "Remove-Item -Force -ErrorAction SilentlyContinue 'C:\\norbourg\\roles\\$role-post.ps1.done'" >/dev/null || true
_winrm_retry "$ip" start "C:\\norbourg\\roles\\$role-post.ps1" || {
fail "$name: could not start $role-post.ps1"
return 1
}
marker=$(_winrm "$ip" wait "C:\\norbourg\\roles\\$role-post.ps1" 3600) || {
fail "$name: $role-post.ps1 did not finish"
return 1