49 lines
1.8 KiB
Scheme
49 lines
1.8 KiB
Scheme
(define-module (ordo play)
|
|
#:use-module (srfi srfi-9)
|
|
#:use-module (srfi srfi-26)
|
|
#:use-module (logging logger)
|
|
#:use-module (ordo connection)
|
|
#:use-module (ordo interceptor)
|
|
#:use-module (ordo interceptor connection)
|
|
#:use-module (ordo inventory)
|
|
#:use-module (ordo util flatten)
|
|
#:export (play
|
|
play?
|
|
play-host
|
|
play-sudo?
|
|
play-sudo-user
|
|
play-sudo-password
|
|
play-vars
|
|
play-interceptors
|
|
run-play))
|
|
|
|
(define-record-type <play>
|
|
(make-play name host sudo? sudo-user sudo-password vars interceptors)
|
|
play?
|
|
(name play-name)
|
|
(host play-host)
|
|
(sudo? play-sudo?)
|
|
(sudo-user play-sudo-user)
|
|
(sudo-password play-sudo-password)
|
|
(vars play-vars)
|
|
(interceptors play-interceptors))
|
|
|
|
(define* (play #:key name host (sudo? #f) (sudo-user #f) (sudo-password #f) (vars '()) (interceptors '()))
|
|
(make-play name host sudo? sudo-user sudo-password vars interceptors))
|
|
|
|
(define (run-play p playbook-vars)
|
|
(log-msg 'NOTICE "Running play: " (play-name p))
|
|
(let ((hosts (resolve-hosts (play-host p))))
|
|
(if (null? hosts)
|
|
(log-msg 'WARN "No hosts matched: " (play-host p))
|
|
(for-each (lambda (h) (run-host-play p h playbook-vars)) hosts))))
|
|
|
|
(define (run-host-play p h playbook-vars)
|
|
(log-msg 'NOTICE "Running play: " (play-name p) " on host: " (host-name h))
|
|
(let ((chain (flatten (cons (connection (host-connection h)
|
|
#:sudo? (play-sudo? p)
|
|
#:sudo-user (play-sudo-user p)
|
|
#:sudo-password (play-sudo-password p))
|
|
(play-interceptors p))))
|
|
(ctx (init-context #:vars (append (play-vars p) playbook-vars))))
|
|
(execute ctx chain)))
|