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.
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#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, dry_run = false, 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, dry_run = false, node_attrs = {}, private_key_paths = []) ⇒ ChefRunner
Returns a new instance of ChefRunner.
23 24 25 26 27 28 29 30 31 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 23 def initialize(cookbook_path, run_list, dry_run=false, 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 @dry_run = dry_run 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 |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
21 22 23 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 21 def dry_run @dry_run 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 67 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 Chef::Config.why_run = dry_run # 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
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 33 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
60 61 62 63 64 65 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 60 def formatter @formatter ||= Chef::EventDispatch::Dispatcher.new.tap do |d| d.register(Chef::Formatters.new(:doc, stdout, stderr)) end end |
#ohai ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 83 def ohai return @ohai if @ohai @ohai = Ohai::System.new @ohai.all_plugins(["platform", "platform_version"]) @ohai end |
#policy ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 49 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
45 46 47 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 45 def run_context @run_context ||= policy.setup_run_context end |
#stderr ⇒ Object
95 96 97 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 95 def stderr $stderr end |
#stdout ⇒ Object
91 92 93 |
# File 'lib/fhcap/chef-dk/chef_runner.rb', line 91 def stdout $stdout end |