Sha256: 62ddf1a380574db49271ac91efb89f45f07936fa77aff22dbed0f6d2d87ff7d5

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

options = {
  :recipe => 'default'
}
opts = OptionParser.new do |opts|
  opts.banner = "Usage: blender mix [OPTIONS] [DIR] HOST"
  opts.separator "Options:"

  opts.on("-r", "--recipe RECIPE", "('default' will be used if RECIPE not specified") do |val|
    options[:recipe] = val
  end

  opts.on("-N", "--node NODE", "force NODE as the current nodename") do |val|
    options[:node] = val
  end

  opts.on("-R", "--roles ROLES", "comma delimited list of roles that should execute") do |val|
    options[:roles] = val
  end

  opts.separator ""
  opts.separator "Common options:"

  opts.on("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.separator ""
  opts.separator "Notes:"
  opts.separator '    "." used if DIR not specified'

end
opts.parse!

dir = ARGV.shift
host = ARGV.shift
abort("unexpected: #{ARGV*" "}\n#{opts}") unless ARGV.empty?
if host.nil?
  host = dir
  dir = "."
end

abort(opts.to_s) unless dir && host

unless File.directory?(dir)
  puts "#{dir} is not a directory"
  abort(opts.to_s)
end

File.file?(File.join(dir, recipe = options[:recipe])) ||
  File.file?(File.join(dir, recipe = "#{options[:recipe]}.rb")) ||
  abort("recipe #{recipe} not found\n#{opts}")

WORK_DIR = "/var/lib/blender/recipes"
LOCAL_MANIFEST_DIR = File.expand_path("../../manifest", __FILE__)
REMOTE_MANIFEST_DIR = "/var/lib/blender/manifest"
ROOT_MANIFEST = File.join(REMOTE_MANIFEST_DIR, "root.rb")

def run(*cmd)
  puts ">> #{cmd * ' '}"
  system(*cmd)
end

run("rsync -azP --delete --exclude '.*' #{LOCAL_MANIFEST_DIR}/ #{host}:#{REMOTE_MANIFEST_DIR}") &&
run("rsync -azP --delete --exclude '.*' --exclude other #{dir}/ #{host}:#{WORK_DIR}") &&

extra=""
extra << " NODE=#{options[:node]}" if options[:node]
extra << " ROLES=#{options[:roles]}" if options[:roles]

run("ssh", host, "echo 'Running Puppet [recipe: #{recipe}]...';cd #{WORK_DIR} && RECIPE=#{recipe} #{extra} shadow_puppet #{ROOT_MANIFEST}")

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
server-blender-0.0.8 lib/blender/cli/mix.rb