ordo/examples/install-aws-cli.scm

41 lines
1.8 KiB
Scheme

(use-modules
(ice-9 filesystem)
(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)
(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 "Install AWS CLI"
#:host "localhost"
#: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")))))))