Parent

Files

Class/Module Index [+]

Quicksearch

Chef::RunContext::CookbookCompiler

Implements the compile phase of the chef run by loading/eval-ing files from cookbooks in the correct order and in the correct context.

Attributes

events[R]
run_list_expansion[R]

Public Class Methods

new(run_context, run_list_expansion, events) click to toggle source
# File lib/chef/run_context/cookbook_compiler.rb, line 34
def initialize(run_context, run_list_expansion, events)
  @run_context = run_context
  @events = events
  @run_list_expansion = run_list_expansion
  @cookbook_order = nil
end

Public Instance Methods

compile() click to toggle source

Run the compile phase of the chef run. Loads files in the following order:

  • Libraries

  • Attributes

  • LWRPs

  • Resource Definitions

  • Recipes

Recipes are loaded in precisely the order specified by the expanded run_list.

Other files are loaded in an order derived from the expanded run_list and the dependencies declared by cookbooks' metadata. See cookbook_order for more information.

# File lib/chef/run_context/cookbook_compiler.rb, line 69
def compile
  compile_libraries
  compile_attributes
  compile_lwrps
  compile_resource_definitions
  compile_recipes
end
compile_attributes() click to toggle source

Loads attributes files from cookbooks. Attributes files are loaded according to cookbook_order; within a cookbook, default.rb is loaded first, then the remaining attributes files in lexical sort order.

# File lib/chef/run_context/cookbook_compiler.rb, line 106
def compile_attributes
  @events.attribute_load_start(count_files_by_segment(:attributes))
  cookbook_order.each do |cookbook|
    load_attributes_from_cookbook(cookbook)
  end
  @events.attribute_load_complete
end
compile_libraries() click to toggle source

Loads library files from cookbooks according to cookbook_order.

# File lib/chef/run_context/cookbook_compiler.rb, line 95
def compile_libraries
  @events.library_load_start(count_files_by_segment(:libraries))
  cookbook_order.each do |cookbook|
    load_libraries_from_cookbook(cookbook)
  end
  @events.library_load_complete
end
compile_lwrps() click to toggle source

Loads LWRPs according to cookbook_order. Providers are loaded before resources on a cookbook-wise basis.

# File lib/chef/run_context/cookbook_compiler.rb, line 116
def compile_lwrps
  lwrp_file_count = count_files_by_segment(:providers) + count_files_by_segment(:resources)
  @events.lwrp_load_start(lwrp_file_count)
  cookbook_order.each do |cookbook|
    load_lwrps_from_cookbook(cookbook)
  end
  @events.lwrp_load_complete
end
compile_recipes() click to toggle source

Iterates over the expanded run_list, loading each recipe in turn.

# File lib/chef/run_context/cookbook_compiler.rb, line 135
def compile_recipes
  @events.recipe_load_start(run_list_expansion.recipes.size)
  run_list_expansion.recipes.each do |recipe|
    begin
      @run_context.load_recipe(recipe)
    rescue Chef::Exceptions::RecipeNotFound => e
      @events.recipe_not_found(e)
      raise
    rescue Exception => e
      path = resolve_recipe(recipe)
      @events.recipe_file_load_failed(path, e)
      raise
    end
  end
  @events.recipe_load_complete
end
compile_resource_definitions() click to toggle source

Loads resource definitions according to cookbook_order

# File lib/chef/run_context/cookbook_compiler.rb, line 126
def compile_resource_definitions
  @events.definition_load_start(count_files_by_segment(:definitions))
  cookbook_order.each do |cookbook|
    load_resource_definitions_from_cookbook(cookbook)
  end
  @events.definition_load_complete
end
cookbook_collection() click to toggle source

Chef::CookbookCollection object for the current run

# File lib/chef/run_context/cookbook_compiler.rb, line 47
def cookbook_collection
  @run_context.cookbook_collection
end
cookbook_order() click to toggle source

Extracts the cookbook names from the expanded run list, then iterates over the list, recursing through dependencies to give a run_list ordered array of cookbook names with no duplicates. Dependencies appear before the cookbook(s) that depend on them.

# File lib/chef/run_context/cookbook_compiler.rb, line 81
def cookbook_order
  @cookbook_order ||= begin
    ordered_cookbooks = []
    seen_cookbooks = {}
    run_list_expansion.recipes.each do |recipe|
      cookbook = Chef::Recipe.parse_recipe_name(recipe).first
      add_cookbook_with_deps(ordered_cookbooks, seen_cookbooks, cookbook)
    end
    Chef::Log.debug("Cookbooks to compile: #{ordered_cookbooks.inspect}")
    ordered_cookbooks
  end
end
definitions() click to toggle source

Resource Definitions from the compiled cookbooks. This is populated by calling compile_resource_definitions (which is called by compile)

# File lib/chef/run_context/cookbook_compiler.rb, line 53
def definitions
  @run_context.definitions
end
node() click to toggle source

Chef::Node object for the current run.

# File lib/chef/run_context/cookbook_compiler.rb, line 42
def node
  @run_context.node
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.