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_DATA_BAG_PATH =
"#{DEST_CHEF_TMP}/data_bags"
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.



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

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

Instance Method Details

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



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

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