Merge branch wip/interceptors into main

This commit is contained in:
Ray Miller 2025-01-26 14:49:07 +00:00
parent 06c2679c64
commit 9faaeab2b0
Signed by: ray
GPG key ID: 043F786C4CD681B8
32 changed files with 680 additions and 471 deletions

View file

@ -1,33 +1,41 @@
(use-modules
(ice-9 filesystem)
(ordo))
(srfi srfi-71)
(ordo playbook)
(ordo play)
(ordo interceptor)
(ordo connection)
(ordo interceptor create-tmp-dir)
(ordo interceptor require-commands)
(ordo interceptor user-info)
(ordo interceptor download)
(ordo interceptor unzip)
(ordo interceptor command))
;; This example shows that a function can act a bit like an ansible role by
;; returning a list of interceptors to be added to the caller's interceptor
;; chain. (The list will be flattened to construct the final chain.)
(define* (install-aws-cli #:key (url "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip") update? install-dir bin-dir)
(let* ((conn (current-connection))
(tmp-dir (run conn "mktemp" "-d" #:return car #:check? #t)))
(dynamic-wind
(const #t)
(lambda ()
(let ((zipfile (file-name-join* tmp-dir (file-basename url))))
(run conn "wget" "-O" zipfile url #:check? #t)
(run conn "unzip" zipfile "-d" tmp-dir #:check? #t)
(run conn (file-name-join* tmp-dir "aws" "install")
(when install-dir `("-i" ,install-dir))
(when bin-dir `("-b" ,bin-dir))
(when update? "-u")
#:check? #t)))
(lambda ()
(run conn "rm" "-rf" tmp-dir)))))
(list (require-commands "wget" "unzip")
(create-tmp-dir #:register 'aws-cli-tmp)
(download "download-aws-cli" #:url url #:target-dir (var aws-cli-tmp) #:register 'aws-cli-zipfile)
(unzip "extract-aws-cli" #:file-name (var aws-cli-zipfile) #:target-dir (var aws-cli-tmp))
(command "run-aws-cli-installer"
(list
(let-vars (aws-cli-tmp) (file-name-join* aws-cli-tmp "aws" "install"))
(when install-dir `("-i" ,install-dir))
(when bin-dir `("-b" ,bin-dir))
(when update? "-u")
#:check? #t))))
(playbook
#:name "Test Playbook"
#:plays (list
(play
#:name "Test play"
#:name "Install AWS CLI"
#:host "localhost"
#:tasks (list
(task #:name "Install AWS CLI"
#:action (lambda ()
(install-aws-cli #:update? #t
#:install-dir (file-name-join* ($ #:fact.home-dir) ".local" "aws-cli")
#:bin-dir (file-name-join* ($ #:fact.home-dir) ".local" "bin"))))))))
#:interceptors (list
(user-info)
(install-aws-cli #:update? #t
#:install-dir (let-vars (user-info) (file-name-join* (assoc-ref user-info #:home-dir) ".local" "aws-cli"))
#:bin-dir (let-vars (user-info) (file-name-join* (assoc-ref user-info #:home-dir) ".local" "bin")))))))