Refactor to use a core namespace with global vars

This commit is contained in:
Ray Miller 2025-01-11 21:00:24 +00:00
parent a65415f846
commit 04a75984cb
Signed by: ray
GPG key ID: 043F786C4CD681B8
3 changed files with 222 additions and 46 deletions

View file

@ -1,44 +1,24 @@
(use-modules
(ice-9 filesystem)
(ordo condition)
(ordo)
(ordo connection)
(ordo context)
(ordo action filesystem)
(ordo play)
(ordo task)
(ordo handler))
(ordo logger))
(define test-play
(play "Test play"
#:connection (local-connection)
#:vars '((base-dir . "/home/ray/ordo-test"))
#:tasks (list
(task "Override base dir"
(const "/home/ray/ordo-test-again")
#:register 'base-dir)
(task "Create test directory"
(bind-context-vars
(base-dir)
(action:install-dir base-dir))
#:condition (bind-context-vars
(base-dir)
(negate (cond:directory? base-dir))))
(task "Create test file from string content"
(bind-context-vars
(base-dir)
(action:install-file (file-name-join* base-dir "foo")
#:content "Hello, world!\n"
#:mode #o600))
#:register 'foo)
(task "Get file status"
(bind-context-vars
(foo)
(action:stat foo))
#:register 'stat-out
#:triggers '(display-stat)))
#:handlers `((display-stat . ,(handler "Display stat"
(bind-context-vars
(foo stat-out)
(lambda _ (pk foo stat-out))))))))
(define test-playbook
(playbook
#:name "Test Playbook"
#:plays (list
(play
#:name "Test play"
#:connection (local-connection)
#:vars '((base-dir . "/home/ray/ordo-test"))
#:acts (list
(act #:name "Act I"
#:tasks (list
(task #:name "Create base directory"
#:action (lambda (c) (must c "mkdir" "-p" ($ 'base-dir))))
(task #:name "Create test file"
#:action (lambda (c) (must c "touch" (file-name-join* ($ 'base-dir) "test-file")))))))))))
(run-play test-play)
(setup-logging)
(perform test-playbook '())