updated the lab-tool to use correct keys

This commit is contained in:
Geir Okkenhaug Jerstad 2025-07-03 22:49:35 +02:00
parent fef22d02b8
commit 62fabf835d
2 changed files with 31 additions and 21 deletions

View file

@ -25,6 +25,8 @@
(define (get-ssh-config machine-name) (define (get-ssh-config machine-name)
"Get SSH configuration for a machine" "Get SSH configuration for a machine"
`((hostname . ,(symbol->string machine-name)) `((hostname . ,(symbol->string machine-name))
(user . "sma")
(identity-file . "~/.ssh/id_ed25519_admin")
(is-local . #f))) (is-local . #f)))
(define (get-homelab-root) (define (get-homelab-root)

View file

@ -27,14 +27,17 @@
(log-debug "Machine ~a is local, skipping SSH test" machine-name) (log-debug "Machine ~a is local, skipping SSH test" machine-name)
#t) #t)
(let ((hostname (assoc-ref ssh-config 'hostname)) (let ((hostname (assoc-ref ssh-config 'hostname))
(ssh-alias (assoc-ref ssh-config 'ssh-alias))) (ssh-alias (assoc-ref ssh-config 'ssh-alias))
(log-debug "Testing SSH connection to ~a (~a)" machine-name hostname) (user (assoc-ref ssh-config 'user))
(identity-file (assoc-ref ssh-config 'identity-file)))
(log-debug "Testing SSH connection to ~a (~a) as ~a using key ~a" machine-name hostname user identity-file)
(catch #t (catch #t
(lambda () (lambda ()
;; Use system ssh command for compatibility with existing configuration (let* ((target (if user (format #f "~a@~a" user hostname) hostname))
(let* ((test-cmd (if ssh-alias (key-arg (if identity-file (format #f "-i ~a" identity-file) ""))
(format #f "ssh -o ConnectTimeout=5 -o BatchMode=yes ~a echo OK" ssh-alias) (test-cmd (if ssh-alias
(format #f "ssh -o ConnectTimeout=5 -o BatchMode=yes ~a echo OK" hostname))) (format #f "ssh -o ConnectTimeout=5 -o BatchMode=yes ~a ~a echo OK" key-arg ssh-alias)
(format #f "ssh -o ConnectTimeout=5 -o BatchMode=yes ~a ~a echo OK" key-arg target)))
(port (open-pipe* OPEN_READ "/bin/sh" "-c" test-cmd)) (port (open-pipe* OPEN_READ "/bin/sh" "-c" test-cmd))
(output (get-string-all port)) (output (get-string-all port))
(status (close-pipe port))) (status (close-pipe port)))
@ -67,15 +70,19 @@
(values (zero? status) output))) (values (zero? status) output)))
;; Remote execution ;; Remote execution
(let ((ssh-alias (assoc-ref ssh-config 'ssh-alias)) (let ((ssh-alias (assoc-ref ssh-config 'ssh-alias))
(hostname (assoc-ref ssh-config 'hostname))) (hostname (assoc-ref ssh-config 'hostname))
(log-debug "Executing on ~a: ~a" machine-name full-command) (user (assoc-ref ssh-config 'user))
(let* ((ssh-cmd (format #f "ssh ~a '~a'" (identity-file (assoc-ref ssh-config 'identity-file)))
(or ssh-alias hostname) (log-debug "Testing SSH connection to ~a (~a) as ~a using key ~a" machine-name hostname user identity-file)
full-command)) (catch #t
(port (open-pipe* OPEN_READ "/bin/sh" "-c" ssh-cmd)) (lambda ()
(output (get-string-all port)) (let* ((target (if user (format #f "~a@~a" user (or ssh-alias hostname)) (or ssh-alias hostname)))
(status (close-pipe port))) (key-arg (if identity-file (format #f "-i ~a" identity-file) ""))
(values (zero? status) output))))))) (ssh-cmd (format #f "ssh ~a ~a '~a'" key-arg target full-command))
(port (open-pipe* OPEN_READ "/bin/sh" "-c" ssh-cmd))
(output (get-string-all port))
(status (close-pipe port)))
(values (zero? status) output)))))))
;; Copy file to remote machine using scp ;; Copy file to remote machine using scp
(define (copy-file-to-remote machine-name local-path remote-path) (define (copy-file-to-remote machine-name local-path remote-path)
@ -93,12 +100,13 @@
(zero? status))) (zero? status)))
;; Remote copy ;; Remote copy
(let ((ssh-alias (assoc-ref ssh-config 'ssh-alias)) (let ((ssh-alias (assoc-ref ssh-config 'ssh-alias))
(hostname (assoc-ref ssh-config 'hostname))) (hostname (assoc-ref ssh-config 'hostname))
(log-debug "Copying to ~a: ~a -> ~a" machine-name local-path remote-path) (user (assoc-ref ssh-config 'user))
(let* ((scp-cmd (format #f "scp '~a' '~a:~a'" (identity-file (assoc-ref ssh-config 'identity-file)))
local-path (log-debug "Copying to ~a: ~a -> ~a as ~a using key ~a" machine-name local-path remote-path user identity-file)
(or ssh-alias hostname) (let* ((target (if user (format #f "~a@~a" user (or ssh-alias hostname)) (or ssh-alias hostname)))
remote-path)) (key-arg (if identity-file (format #f "-i ~a" identity-file) ""))
(scp-cmd (format #f "scp ~a '~a' '~a:~a'" key-arg local-path target remote-path))
(status (system scp-cmd))) (status (system scp-cmd)))
(if (zero? status) (if (zero? status)
(begin (begin