Class: Spatula::Cook

Inherits:
SshCommand show all
Defined in:
lib/spatula/cook.rb

Overview

Where to find upstream cookbooks

Instance Method Summary collapse

Methods inherited from SshCommand

run, #ssh, #ssh_command, #ssh_opts

Constructor Details

#initialize(server, node, port = nil, login = nil, identity = nil, log_level = nil) ⇒ Cook

Returns a new instance of Cook.



6
7
8
9
10
# File 'lib/spatula/cook.rb', line 6

def initialize(server, node, port=nil, =nil, identity=nil, log_level=nil)
  super(server, port, , identity)
  @node = node
  @log_level = log_level
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spatula/cook.rb', line 12

def run
  Dir["**/*.rb"].each do |recipe|
    ok = sh "ruby -c #{recipe} >/dev/null 2>&1"
    raise "Syntax error in #{recipe}" if not ok
  end

  Dir["**/*.json"].each do |json|
    begin
      require 'json'
      # parse without instantiating Chef classes
      JSON.parse File.read(json), :create_additions => false
    rescue => error
      raise "Syntax error in #{json}: #{error.message}"
    end
  end

  if @server =~ /^local$/i
    sh chef_cmd
  else
    sh "rsync -rlP --rsh=\"ssh #{ssh_opts}\" --delete --exclude '.*' ./ #@server:#{REMOTE_CHEF_PATH}"
    ssh "cd #{REMOTE_CHEF_PATH}; #{chef_cmd}"
  end
end