Files

Class/Module Index [+]

Quicksearch

Chef::Application::Apply

Public Class Methods

new() click to toggle source
# File lib/chef/application/apply.rb, line 77
def initialize
  super
end

Public Instance Methods

get_recipe_and_run_context() click to toggle source
# File lib/chef/application/apply.rb, line 96
def get_recipe_and_run_context
  Chef::Config[:solo] = true
  @chef_client = Chef::Client.new
  @chef_client.run_ohai
  @chef_client.load_node
  @chef_client.build_node
  run_context = if @chef_client.events.nil?
                  Chef::RunContext.new(@chef_client.node, {})
                else
                  Chef::RunContext.new(@chef_client.node, {}, @chef_client.events)
                end
  recipe = Chef::Recipe.new("(chef-apply cookbook)", "(chef-apply recipe)", run_context)
  [recipe, run_context]
end
read_recipe_file(file_name) click to toggle source
# File lib/chef/application/apply.rb, line 85
def read_recipe_file(file_name)
  recipe_path = file_name
  unless File.exist?(recipe_path)
    Chef::Application.fatal!("No file exists at #{recipe_path}", 1)
  end
  recipe_path = File.expand_path(recipe_path)
  recipe_fh = open(recipe_path)
  recipe_text = recipe_fh.read
  [recipe_text, recipe_fh]
end
reconfigure() click to toggle source
# File lib/chef/application/apply.rb, line 81
def reconfigure
  configure_logging
end
run() click to toggle source

Get this party started

# File lib/chef/application/apply.rb, line 155
def run
  reconfigure
  run_application
end
run_application() click to toggle source
# File lib/chef/application/apply.rb, line 141
def run_application
  begin
    parse_options
    run_chef_recipe
    Chef::Application.exit! "Exiting", 0
  rescue SystemExit => e
    raise
  rescue Exception => e
    Chef::Application.debug_stacktrace(e)
    Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
  end
end
run_chef_recipe() click to toggle source
# File lib/chef/application/apply.rb, line 120
def run_chef_recipe
  if config[:execute]
    @recipe_text = config[:execute]
    temp_recipe_file
  elsif config[:stdin]
    @recipe_text = STDIN.read
    temp_recipe_file
  else
    @recipe_filename = ARGV[0]
    @recipe_text,@recipe_fh = read_recipe_file @recipe_filename
  end
  recipe,run_context = get_recipe_and_run_context
  recipe.instance_eval(@recipe_text, @recipe_filename, 1)
  runner = Chef::Runner.new(run_context)
  begin
    runner.converge
  ensure
    @recipe_fh.close
  end
end
temp_recipe_file() click to toggle source

write recipe to temp file, so in case of error, user gets error w/ context

# File lib/chef/application/apply.rb, line 113
def temp_recipe_file
  @recipe_fh = Tempfile.open('recipe-temporary-file')
  @recipe_fh.write(@recipe_text)
  @recipe_fh.rewind
  @recipe_filename = @recipe_fh.path
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.