Class: ChefDK::ChefRunner
- Inherits:
-
Object
- Object
- ChefDK::ChefRunner
- Defined in:
- lib/chef-dk/chef_runner.rb
Overview
An adapter to chef’s APIs to kick off a chef-client run.
Instance Attribute Summary collapse
-
#cookbook_path ⇒ Object
readonly
Returns the value of attribute cookbook_path.
-
#run_list ⇒ Object
readonly
Returns the value of attribute run_list.
Instance Method Summary collapse
- #configure ⇒ Object
- #converge ⇒ Object
- #formatter ⇒ Object
-
#initialize(cookbook_path, run_list) ⇒ ChefRunner
constructor
A new instance of ChefRunner.
- #ohai ⇒ Object
- #policy ⇒ Object
- #run_context ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
Constructor Details
#initialize(cookbook_path, run_list) ⇒ ChefRunner
Returns a new instance of ChefRunner.
29 30 31 32 33 34 |
# File 'lib/chef-dk/chef_runner.rb', line 29 def initialize(cookbook_path, run_list) @cookbook_path = File.(cookbook_path) @run_list = run_list @formatter = nil @ohai = nil end |
Instance Attribute Details
#cookbook_path ⇒ Object (readonly)
Returns the value of attribute cookbook_path.
26 27 28 |
# File 'lib/chef-dk/chef_runner.rb', line 26 def cookbook_path @cookbook_path end |
#run_list ⇒ Object (readonly)
Returns the value of attribute run_list.
27 28 29 |
# File 'lib/chef-dk/chef_runner.rb', line 27 def run_list @run_list end |
Instance Method Details
#configure ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef-dk/chef_runner.rb', line 68 def configure Chef::Config.solo = true Chef::Config.cookbook_path = cookbook_path Chef::Config.color = true Chef::Config.diff_disabled = true # atomic file operations on Windows require Administrator privileges to be able to read the SACL from a file # Using file_staging_uses_destdir(true) will get us inherited permissions indirectly on tempfile creation Chef::Config.file_atomic_update = false if Chef::Platform.windows? Chef::Config.file_staging_uses_destdir = true # Default in Chef 12+ end |
#converge ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/chef-dk/chef_runner.rb', line 36 def converge configure Chef::Runner.new(run_context).converge rescue Chef::Exceptions::CookbookNotFound => e = "Could not find cookbook(s) to satisfy run list #{run_list.inspect} in #{cookbook_path}" raise CookbookNotFound.new(, e) rescue => e raise ChefConvergeError.new("Chef failed to converge: #{e}", e) end |
#formatter ⇒ Object
61 62 63 64 65 66 |
# File 'lib/chef-dk/chef_runner.rb', line 61 def formatter @formatter ||= Chef::EventDispatch::Dispatcher.new.tap do |d| d.register(Chef::Formatters.new(:doc, stdout, stderr)) end end |
#ohai ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/chef-dk/chef_runner.rb', line 80 def ohai return @ohai if @ohai @ohai = Ohai::System.new @ohai.all_plugins(["platform", "platform_version"]) @ohai end |
#policy ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chef-dk/chef_runner.rb', line 50 def policy return @policy_builder if @policy_builder @policy_builder = Chef::PolicyBuilder::ExpandNodeObject.new("chef-dk", ohai.data, {}, nil, formatter) @policy_builder.load_node @policy_builder.build_node @policy_builder.node.run_list(*run_list) @policy_builder. @policy_builder end |
#run_context ⇒ Object
46 47 48 |
# File 'lib/chef-dk/chef_runner.rb', line 46 def run_context @run_context ||= policy.setup_run_context end |
#stderr ⇒ Object
92 93 94 |
# File 'lib/chef-dk/chef_runner.rb', line 92 def stderr $stderr end |
#stdout ⇒ Object
88 89 90 |
# File 'lib/chef-dk/chef_runner.rb', line 88 def stdout $stdout end |