Class: Toft::Chef::ChefRunner

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/toft/chef/chef_runner.rb

Constant Summary collapse

DEST_CHEF_TMP =
"/tmp/toft-chef-tmp"
DEST_COOKBOOK_PATH =
"#{DEST_CHEF_TMP}/cookbooks"
DEST_ROLE_PATH =
"#{DEST_CHEF_TMP}/roles"
DEST_CHEF_SOLO_PATH =
"#{DEST_CHEF_TMP}/solo.rb"
DEST_CHEF_JSON_PATH =
"#{DEST_CHEF_TMP}/solo.json"

Instance Method Summary collapse

Constructor Details

#initialize(root_dir, &command_runner) ⇒ ChefRunner

Returns a new instance of ChefRunner.



15
16
17
18
# File 'lib/toft/chef/chef_runner.rb', line 15

def initialize(root_dir, &command_runner)
  @root_dir = root_dir
  @command_runner = command_runner
end

Instance Method Details

#run(run_list, params = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/toft/chef/chef_runner.rb', line 20

def run(run_list, params = {})
  override_attributes_hash = parse_attributes params[:json], params[:attributes] 
  copy_chef_material
  generate_solo_rb
  generate_json ([] << run_list).flatten, override_attributes_hash
  @command_runner.call "chef-solo -c #{DEST_CHEF_SOLO_PATH} -j #{DEST_CHEF_JSON_PATH}"
end