Class: Fhcap::ChefRunner
- Inherits:
-
Object
- Object
- Fhcap::ChefRunner
- Defined in:
- lib/fhcap/chef-dk/chef_runner.rb
Instance Attribute Summary collapse
-
#cookbook_path ⇒ Object
readonly
Returns the value of attribute cookbook_path.
-
#node_attrs ⇒ Object
readonly
Returns the value of attribute node_attrs.
-
#private_key_paths ⇒ Object
readonly
Returns the value of attribute private_key_paths.
-
#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, node_attrs = {}, private_key_paths = []) ⇒ 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, node_attrs = {}, private_key_paths = []) ⇒ ChefRunner
Returns a new instance of ChefRunner.
22 23 24 25 26 27 28 29 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 22 def initialize(cookbook_path, run_list, node_attrs={}, private_key_paths=[]) @cookbook_path = File.(cookbook_path) @run_list = run_list @private_key_paths = private_key_paths @node_attrs = node_attrs @formatter = nil @ohai = nil end |
Instance Attribute Details
#cookbook_path ⇒ Object (readonly)
Returns the value of attribute cookbook_path.
17 18 19 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 17 def cookbook_path @cookbook_path end |
#node_attrs ⇒ Object (readonly)
Returns the value of attribute node_attrs.
20 21 22 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 20 def node_attrs @node_attrs end |
#private_key_paths ⇒ Object (readonly)
Returns the value of attribute private_key_paths.
19 20 21 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 19 def private_key_paths @private_key_paths end |
#run_list ⇒ Object (readonly)
Returns the value of attribute run_list.
18 19 20 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 18 def run_list @run_list end |
Instance Method Details
#configure ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 65 def configure Chef::Config.solo = true Chef::Config.log_level = :error Chef::Config.ssl_verify_mode = :verify_none Chef::Config.cookbook_path = cookbook_path Chef::Config.private_key_paths = (Chef::Config.private_key_paths + private_key_paths).compact.uniq 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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 31 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() rescue => e test = ChefConvergeError.new("Chef failed to converge: #{e}") puts e.backtrace raise test end |
#formatter ⇒ Object
58 59 60 61 62 63 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 58 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/fhcap/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
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 47 def policy return @policy_builder if @policy_builder @policy_builder = Chef::PolicyBuilder::ExpandNodeObject.new("fhcap-cli", ohai.data, node_attrs, 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
43 44 45 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 43 def run_context @run_context ||= policy.setup_run_context end |
#stderr ⇒ Object
92 93 94 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 92 def stderr $stderr end |
#stdout ⇒ Object
88 89 90 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 88 def stdout $stdout end |