Merge branch wip/interceptors into main
This commit is contained in:
parent
06c2679c64
commit
9faaeab2b0
32 changed files with 680 additions and 471 deletions
|
@ -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")))))))
|
||||
|
|
34
examples/interceptor.scm
Normal file
34
examples/interceptor.scm
Normal file
|
@ -0,0 +1,34 @@
|
|||
(use-modules
|
||||
(ice-9 filesystem)
|
||||
(ordo playbook)
|
||||
(ordo play)
|
||||
(ordo interceptor)
|
||||
(ordo interceptor install-file)
|
||||
(ordo interceptor create-tmp-dir)
|
||||
(ordo interceptor stat-file)
|
||||
(ordo interceptor user-info)
|
||||
(ordo interceptor command)
|
||||
(ordo interceptor debug))
|
||||
|
||||
(playbook
|
||||
#:name "Test some basic filesystem operations"
|
||||
#:vars '((file-content . "This is shadowed by the play variable."))
|
||||
#:plays (list (play
|
||||
#:name "Basic filesystem operations"
|
||||
#:host "localhost"
|
||||
#:vars '((file-content . "Hello, world!\n"))
|
||||
#:interceptors (list (create-tmp-dir #:register 'tmp-dir)
|
||||
(user-info)
|
||||
(debug-vars 'user-info)
|
||||
(install-file
|
||||
"install-hello"
|
||||
#:path (let-vars (tmp-dir) (file-name-join* tmp-dir "hello.txt"))
|
||||
#:content (var file-content)
|
||||
#:register 'hello)
|
||||
(stat-file
|
||||
"stat-hello"
|
||||
#:path (var hello)
|
||||
#:register 'hello-stat)
|
||||
(command "list-tmp-dir" (list "ls" "-l" (var tmp-dir) #:check? #t) #:register 'dir-list)
|
||||
(command "list-root-dir" (list "ls" "-l" "/root" #:check? #f) #:register 'root-list)
|
||||
(debug-vars)))))
|
|
@ -1,4 +1,5 @@
|
|||
(use-modules (ordo))
|
||||
(use-modules (ordo inventory)
|
||||
(ordo connection))
|
||||
|
||||
(add-host! "little-rascal"
|
||||
(local-connection)
|
||||
|
|
15
examples/ubuntu.scm
Normal file
15
examples/ubuntu.scm
Normal file
|
@ -0,0 +1,15 @@
|
|||
(use-modules
|
||||
(ordo playbook)
|
||||
(ordo play)
|
||||
(ordo interceptor apt))
|
||||
|
||||
(playbook
|
||||
#:name "APT operations"
|
||||
#:plays (list
|
||||
(play
|
||||
#:name "Test APT operations"
|
||||
#:host '(tagged/any #:ubuntu #:debian)
|
||||
#:interceptors (list
|
||||
(apt:update)
|
||||
(apt:dist-upgrade)
|
||||
(map apt:install (list "curl" "ca-certificates"))))))
|
Loading…
Add table
Add a link
Reference in a new issue