Skip to content

Passing arguments to packages

yyyc514 edited this page Apr 14, 2013 · 8 revisions

This only works with sprinkle 0.5.0 or newer.

policy :websites, :roles => :web_server do
  requires :nginx_site, 1, 2, 3, :site_name => 'somesite.com'
end

package :nginx_site do
  runner "mkdir -p /var/www/#{opts[:site_name]}"
  runner "count #{args.join(" ")}" # calls "count 1 2 3"
end

Arguments are processed with extract_options! and split into args and opts. This API is subject to change. Right now the entire hash you pass is available as opts but in the future some keys sprinkle might want to use internally could reserved, such as :version, etc.

Allowing configurable versions of a package via arguments

package :git do
  version "2.9"
  source "http://git.com/downloads/git-#{opts[:my_version] || version}"
end

policy :gitbox, :servers do
  requires :git, :my_version => "3.0"
end

:version may be reserved in the future for allowing multiple versions of packages to be defined at the same time and allowing a policy to select which versions it wants - hence the above example uses :my_version.

Clone this wiki locally