Inprovise Fork
This project implements an extension for the Inprovise provisioning tool providing a fork
method to the execution contexts
of Inprovise scripts allowing scripts to fork off provisioning commands (apply
, revert
, validate
or trigger
) for
other nodes.
Installation
$ gem install inprovise-fork
Usage
Add the following to (for example) your Inprovise project's rigrc
file.
require 'inprovise/fork'
Syntax
fork(mode = :sync).apply('script', 'name'[, 'name'[, ...]][, config={}])
fork(mode = :sync).revert('script', 'name'[, 'name'[, ...]][, config={}])
fork(mode = :sync).validate('script', 'name'[, 'name'[, ...]][, config={}])
fork(mode = :sync).trigger('action', 'name'[, 'name'[, ...]][, config={}])
or
fork(mode = :sync) do
apply('script', 'name'[, 'name'[, ...]][, config={}])
end
fork(mode = :sync) do
revert('script', 'name'[, 'name'[, ...]][, config={}])
end
fork(mode = :sync) do
validate('script', 'name'[, 'name'[, ...]][, config={}])
end
fork(mode = :sync) do
trigger('action', 'name'[, 'name'[, ...]][, config={}])
end
The mode
argument can be :sync
(default) or :async
. With the first the provisioning methods will not return
until the provisioning process they kicked off has finished. With the latter the provisioning methods kick off the
provisioning process in parallel and return immediately.
The provisioning methods return a reference to the forking execution context allowing provisioning methods to be
chained like:
fork.apply('script', 'node1').trigger('action', 'node1')
Example
By combining the Inprovise-VBox plugin and the Inprovise-Fork plugin
provisioning scripts could add a virtual machine on a host server, register an Inprovise node and provision that new node with a single
rig
command using a scheme like this:
include 'rubysetup.rb'
script 'vmSetup' do
validate do
trigger 'gem:exists', 'rails'
end
apply do
trigger 'gem:install', 'rails'
end
revert do
trigger 'gem:uninstall', 'rails'
end
end
vbox 'myVM' do
configuration ({
:name => 'MyVM',
:image => '/remote/image/path/MyVM.qcow2',
:memory => 1024,
:cpus => 2
})
apply do
fork(:async).apply('vmSetup', 'MyVM')
end
revert do
fork(:sync).revert('vmSetup', 'MyVM')
end
end
end