Class: Chef::Client

Inherits:
Object
  • Object
show all
Extended by:
Mixin::Deprecation
Includes:
Mixin::Deprecation, Mixin::PathSanity
Defined in:
lib/chef/client.rb

Overview

Chef::Client

The main object in a Chef run. Preps a Chef::Node and Chef::RunContext, syncs cookbooks if necessary, and triggers convergence.

Direct Known Subclasses

Shell::DoppelGangerClient

Constant Summary collapse

STDOUT_FD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

IO stream that will be used as ‘STDOUT’ for formatters. Formatters are configured during ‘initialize`, so this provides a convenience for setting alternative IO stream during tests.

STDOUT
STDERR_FD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

IO stream that will be used as ‘STDERR’ for formatters. Formatters are configured during ‘initialize`, so this provides a convenience for setting alternative IO stream during tests.

STDERR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Deprecation

deprecated_attr, deprecated_attr_reader, deprecated_attr_writer, deprecated_ivar

Methods included from Mixin::PathSanity

#enforce_path_sanity

Constructor Details

#initialize(json_attribs = nil, args = {}) ⇒ Client

Creates a new Chef::Client.

Parameters:

  • json_attribs (Hash) (defaults to: nil)

    Node attributes to layer into the node when it is fetched.

  • args (Hash) (defaults to: {})

    Options:

Options Hash (args):

  • :override_runlist (Array<RunList::RunListItem>)

    A runlist to use instead of the node’s embedded run list.

  • :specific_recipes (Array<String>)

    A list of recipe file paths to load after the run list has been loaded.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/chef/client.rb', line 155

def initialize(json_attribs = nil, args = {})
  @json_attribs = json_attribs || {}
  @ohai = Ohai::System.new

  event_handlers = configure_formatters + configure_event_loggers
  event_handlers += Array(Chef::Config[:event_handlers])

  @events = EventDispatch::Dispatcher.new(*event_handlers)
  # TODO it seems like a bad idea to be deletin' other peoples' hashes.

  @override_runlist = args.delete(:override_runlist)
  @specific_recipes = args.delete(:specific_recipes)
  @run_status = Chef::RunStatus.new(nil, events)

  if new_runlist = args.delete(:runlist)
    @json_attribs["run_list"] = new_runlist
  end
end

Instance Attribute Details

#eventsEventDispatch::Dispatcher (readonly)

The event dispatcher for the Chef run, including any configured output formatters and event loggers.

TODO add stdout, stderr, and default formatters to Chef::Config so the defaults aren’t calculated here. Remove force_logger and force_formatter from this code.

Returns:

See Also:

  • Formatters
  • Chef::Config#formatters
  • Chef::Config#stdout
  • Chef::Config#stderr
  • Chef::Config#force_logger
  • Chef::Config#force_formatter
  • EventLoggers
  • Chef::Config#disable_event_logger
  • Chef::Config#event_loggers
  • Chef::Config#event_handlers


142
143
144
# File 'lib/chef/client.rb', line 142

def events
  @events
end

#json_attribsHash (readonly)

Extra node attributes that were applied to the node.

Returns:

  • (Hash)


120
121
122
# File 'lib/chef/client.rb', line 120

def json_attribs
  @json_attribs
end

#ohaiOhai::System (readonly)

The ohai system used by this client.

Returns:

  • (Ohai::System)


91
92
93
# File 'lib/chef/client.rb', line 91

def ohai
  @ohai
end

#restChef::ServerAPI (readonly)

The rest object used to communicate with the Chef server.

Returns:



98
99
100
# File 'lib/chef/client.rb', line 98

def rest
  @rest
end

#rest_clean(client_name = node_name, config = Chef::Config) ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rest client for use by API reporters. This rest client will not fail with an exception if it is fed non-UTF8 data.



106
107
108
# File 'lib/chef/client.rb', line 106

def rest_clean
  @rest_clean
end

#run_statusChef::RunStatus (readonly)

The status of the Chef run.

Returns:



71
72
73
# File 'lib/chef/client.rb', line 71

def run_status
  @run_status
end

#runnerChef::Runner

The runner used to converge.

Returns:



113
114
115
# File 'lib/chef/client.rb', line 113

def runner
  @runner
end

Class Method Details

.clear_notificationsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clears all listeners for client run status events.

Primarily for testing purposes.



833
834
835
836
837
# File 'lib/chef/client.rb', line 833

def clear_notifications
  @run_start_notifications = nil
  @run_completed_successfully_notifications = nil
  @run_failed_notifications = nil
end

.run_completed_successfully_notificationsArray<Proc>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Listeners to be run when the client run completes successfully.

Returns:

  • (Array<Proc>)


861
862
863
# File 'lib/chef/client.rb', line 861

def run_completed_successfully_notifications
  @run_completed_successfully_notifications ||= []
end

.run_failed_notificationsArray<Proc>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Listeners to be run when the client run fails.

Returns:

  • (Array<Proc>)


872
873
874
# File 'lib/chef/client.rb', line 872

def run_failed_notifications
  @run_failed_notifications ||= []
end

.run_start_notificationsArray<Proc>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Listeners to be run when the client run starts.

Returns:

  • (Array<Proc>)


850
851
852
# File 'lib/chef/client.rb', line 850

def run_start_notifications
  @run_start_notifications ||= []
end

.when_run_completes_successfully(&notification_block) {|run_status| ... } ⇒ Object

Add a listener for the ‘client run success’ event.

Parameters:

  • notification_block

    The callback (takes |run_status| parameter).

Yield Parameters:



812
813
814
# File 'lib/chef/client.rb', line 812

def when_run_completes_successfully(&notification_block)
  run_completed_successfully_notifications << notification_block
end

.when_run_fails(&notification_block) {|run_status| ... } ⇒ Object

Add a listener for the ‘client run failed’ event.

Parameters:

  • notification_block

    The callback (takes |run_status| parameter).

Yield Parameters:



822
823
824
# File 'lib/chef/client.rb', line 822

def when_run_fails(&notification_block)
  run_failed_notifications << notification_block
end

.when_run_starts(&notification_block) {|run_status| ... } ⇒ Object

Add a listener for the ‘client run started’ event.

Parameters:

  • notification_block

    The callback (takes |run_status| parameter).

Yield Parameters:



802
803
804
# File 'lib/chef/client.rb', line 802

def when_run_starts(&notification_block)
  run_start_notifications << notification_block
end

Instance Method Details

#build_nodeChef::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Mutates the ‘node` object to prepare it for the chef run.

Returns:

See Also:

  • PolicyBuilder#build_node


481
482
483
484
485
# File 'lib/chef/client.rb', line 481

def build_node
  policy_builder.build_node
  run_status.node = node
  node
end

#configure_event_loggersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/chef/client.rb', line 381

def configure_event_loggers
  if Chef::Config.disable_event_logger
    []
  else
    Chef::Config.event_loggers.map do |evt_logger|
      case evt_logger
      when Symbol
        Chef::EventLoggers.new(evt_logger)
      when Class
        evt_logger.new
      else
      end
    end
  end
end

#configure_formattersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



350
351
352
353
354
355
356
357
358
359
360
# File 'lib/chef/client.rb', line 350

def configure_formatters
  formatters_for_run.map do |formatter_name, output_path|
    if output_path.nil?
      Chef::Formatters.new(formatter_name, STDOUT_FD, STDERR_FD)
    else
      io = File.open(output_path, "a+")
      io.sync = true
      Chef::Formatters.new(formatter_name, io, io)
    end
  end
end

#converge(run_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converges all compiled resources.

Fires the converge_start, converge_complete and converge_failed events.

If the exception ‘:end_client_run_early` is thrown during convergence, it does not mark the run complete or failed, and returns `nil`

Parameters:

  • run_context

    The run context.

Returns:

  • The thrown exception, if we are in audit mode. ‘nil` means the converge was successful or ended early.

Raises:

  • Any converge exception, unless we are in audit mode, in which case we return the exception.

See Also:

  • Runner#converge
  • Chef::Config#audit_mode
  • EventDispatch#converge_start
  • EventDispatch#converge_complete
  • EventDispatch#converge_failed


661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/chef/client.rb', line 661

def converge(run_context)
  converge_exception = nil
  catch(:end_client_run_early) do
    begin
      events.converge_start(run_context)
      Chef::Log.debug("Converging node #{node_name}")
      @runner = Chef::Runner.new(run_context)
      @runner.converge
      events.converge_complete
    rescue Exception => e
      events.converge_failed(e)
      raise e if Chef::Config[:audit_mode] == :disabled
      converge_exception = e
    end
  end
  converge_exception
end

#converge_and_save(run_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converge the node via and then save it if successful.

We don’t want to change the old API on the ‘converge` method to have it perform saving. So we wrap it in this method. TODO given this seems to be pretty internal stuff, how badly do we need to split this stuff up?

Parameters:

  • run_context

    The run context.

Returns:

  • The thrown exception, if we are in audit mode. ‘nil` means the converge was successful or ended early.

Raises:

  • Any converge or node save exception, unless we are in audit mode, in which case we return the exception.

See Also:

  • #converge
  • #save_updated_mode
  • Chef::Config#audit_mode


701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/chef/client.rb', line 701

def converge_and_save(run_context)
  converge_exception = converge(run_context)
  unless converge_exception
    begin
      save_updated_node
    rescue Exception => e
      raise e if Chef::Config[:audit_mode] == :disabled
      converge_exception = e
    end
  end
  converge_exception
end

#default_formatterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



372
373
374
375
376
377
378
# File 'lib/chef/client.rb', line 372

def default_formatter
  if (STDOUT.tty? && !Chef::Config[:force_logger]) || Chef::Config[:force_formatter]
    [:doc]
  else
    [:null]
  end
end

#do_windows_admin_checkObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the user has Administrator privileges on windows.

Throws an error if the user is not an admin, and ‘Chef::Config.fatal_windows_admin_check` is true.

Raises:

See Also:

  • platform#windows?
  • Chef::Config#fatal_windows_admin_check


775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/chef/client.rb', line 775

def do_windows_admin_check
  if Chef::Platform.windows?
    Chef::Log.debug("Checking for administrator privileges....")

    if !has_admin_privileges?
      message = "chef-client doesn't have administrator privileges on node #{node_name}."
      if Chef::Config[:fatal_windows_admin_check]
        Chef::Log.fatal(message)
        Chef::Log.fatal("fatal_windows_admin_check is set to TRUE.")
        raise Chef::Exceptions::WindowsNotAdmin, message
      else
        Chef::Log.warn("#{message} This might cause unexpected resource failures.")
      end
    else
      Chef::Log.debug("chef-client has administrator privileges on node #{node_name}.")
    end
  end
end

#expanded_run_listChef::RunListExpansion

Expands the run list.

Returns:

  • (Chef::RunListExpansion)

    The expanded run list.

See Also:

  • PolicyBuilder#expand_run_list


758
759
760
# File 'lib/chef/client.rb', line 758

def expanded_run_list
  policy_builder.expand_run_list
end

#formatters_for_runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



363
364
365
366
367
368
369
# File 'lib/chef/client.rb', line 363

def formatters_for_run
  if Chef::Config.formatters.empty?
    [default_formatter]
  else
    Chef::Config.formatters
  end
end

#load_nodeChef::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiates a Chef::Node object, possibly loading the node’s prior state when using chef-client. Sets Chef.node to the new node.

Returns:

  • (Chef::Node)

    The node object for this Chef run

See Also:

  • PolicyBuilder#load_node


465
466
467
468
469
470
# File 'lib/chef/client.rb', line 465

def load_node
  policy_builder.load_node
  run_status.node = policy_builder.node
  Chef.set_node(policy_builder.node)
  node
end

#nodeChef::Node

The node represented by this client.

Returns:



78
79
80
# File 'lib/chef/client.rb', line 78

def node
  run_status.node
end

#node=(value) ⇒ Object



82
83
84
# File 'lib/chef/client.rb', line 82

def node=(value)
  run_status.node = value
end

#node_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Figure out the node name we are working with.

It tries these, in order:

Raises:

See Also:

  • Chef::Config#node_name


579
580
581
582
583
584
585
586
# File 'lib/chef/client.rb', line 579

def node_name
  name = Chef::Config[:node_name] || ohai[:fqdn] || ohai[:machinename] || ohai[:hostname]
  Chef::Config[:node_name] = name

  raise Chef::Exceptions::CannotDetermineNodeName unless name

  name
end

#policy_builderChef::PolicyBuilder::Policyfile, Chef::PolicyBuilder::ExpandNodeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The PolicyBuilder strategy for figuring out run list and cookbooks.



522
523
524
# File 'lib/chef/client.rb', line 522

def policy_builder
  @policy_builder ||= Chef::PolicyBuilder::Dynamic.new(node_name, ohai.data, json_attribs, override_runlist, events)
end

#register(client_name = node_name, config = Chef::Config) ⇒ Chef::ServerAPI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determine our private key and set up the connection to the Chef server.

Skips registration and fires the ‘skipping_registration` event if Chef::Config.client_key is unspecified or already exists.

If Chef::Config.client_key does not exist, we register the client with the Chef server and fire the registration_start and registration_completed events.

Returns:

See Also:

  • Chef::Config#chef_server_url
  • Chef::Config#client_key
  • ApiClient::Registration#run
  • EventDispatcher#skipping_registration
  • EventDispatcher#registration_start
  • EventDispatcher#registration_completed
  • EventDispatcher#registration_failed


609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/chef/client.rb', line 609

def register(client_name = node_name, config = Chef::Config)
  if !config[:client_key]
    events.skipping_registration(client_name, config)
    Chef::Log.debug("Client key is unspecified - skipping registration")
  elsif File.exists?(config[:client_key])
    events.skipping_registration(client_name, config)
    Chef::Log.debug("Client key #{config[:client_key]} is present - skipping registration")
  else
    events.registration_start(node_name, config)
    Chef::Log.info("Client key #{config[:client_key]} is not present - registering")
    Chef::ApiClient::Registration.new(node_name, config[:client_key]).run
    events.registration_completed
  end
  # We now have the client key, and should use it from now on.

  @rest = Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name,
                                                        signing_key_filename: config[:client_key])
  # force initialization of the rest_clean API object

  rest_clean(client_name, config)
  register_reporters
rescue Exception => e
  # TODO this should probably only ever fire if we *started* registration.

  # Move it to the block above.

  # TODO: munge exception so a semantic failure message can be given to the

  # user

  events.registration_failed(client_name, e, config)
  raise
end

#register_reportersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resource reporters send event information back to the chef server for processing. Can only be called after we have a @rest object



410
411
412
413
414
415
416
417
# File 'lib/chef/client.rb', line 410

def register_reporters
  [
    Chef::ResourceReporter.new(rest_clean),
    Chef::Audit::AuditReporter.new(rest_clean),
  ].each do |r|
    events.register(r)
  end
end

#runObject

Do a full run for this Chef::Client.

Locks the run while doing its job.

Fires run_start before doing anything and fires run_completed or run_failed when finished. Also notifies client listeners of run_started at the beginning of Compile, and run_completed_successfully or run_failed when all is complete.

Phase 1: Setup


Gets information about the system and the run we are doing.

  1. Run ohai to collect system information.

  2. Register / connect to the Chef server (unless in solo mode).

  3. Retrieve the node (or create a new one).

  4. Merge in json_attribs, Chef::Config.environment, and override_run_list.

Phase 2: Compile


Decides what we plan to converge by compiling recipes.

  1. Sync required cookbooks to the local cache.

  2. Load libraries from all cookbooks.

  3. Load attributes from all cookbooks.

  4. Load LWRPs from all cookbooks.

  5. Load resource definitions from all cookbooks.

  6. Load recipes in the run list.

  7. Load recipes from the command line.

Phase 3: Converge


Brings the system up to date.

  1. Converge the resources built from recipes in Phase 2.

  2. Save the node.

  3. Reboot if we were asked to.

Phase 4: Audit


Runs ‘control_group’ audits in recipes. This entire section can be enabled or disabled with config.

  1. ‘control_group’ DSL collects audits during Phase 2

  2. Audits are run using RSpec

  3. Errors are collected and reported using the formatters

Returns:

  • Always returns true.

Raises:

See Also:



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/chef/client.rb', line 243

def run
  start_profiling

  run_error = nil

  runlock = RunLock.new(Chef::Config.lockfile)
  # TODO feels like acquire should have its own block arg for this

  runlock.acquire
  # don't add code that may fail before entering this section to be sure to release lock

  begin
    runlock.save_pid

    request_id = Chef::RequestID.instance.request_id
    run_context = nil
    events.run_start(Chef::VERSION)
    Chef::Log.info("*** Chef #{Chef::VERSION} ***")
    Chef::Log.info "Chef-client pid: #{Process.pid}"
    Chef::Log.debug("Chef-client request_id: #{request_id}")
    enforce_path_sanity
    run_ohai

    register unless Chef::Config[:solo]

    load_node

    build_node

    run_status.run_id = request_id
    run_status.start_clock
    Chef::Log.info("Starting Chef Run for #{node.name}")
    run_started

    do_windows_admin_check

    run_context = setup_run_context

    if Chef::Config[:audit_mode] != :audit_only
      converge_error = converge_and_save(run_context)
    end

    if Chef::Config[:why_run] == true
      # why_run should probably be renamed to why_converge

      Chef::Log.debug("Not running controls in 'why-run' mode - this mode is used to see potential converge changes")
    elsif Chef::Config[:audit_mode] != :disabled
      audit_error = run_audits(run_context)
    end

    # Raise converge_error so run_failed reporters/events are processed.

    raise converge_error if converge_error

    run_status.stop_clock
    Chef::Log.info("Chef Run complete in #{run_status.elapsed_time} seconds")
    run_completed_successfully
    events.run_completed(node)

    # keep this inside the main loop to get exception backtraces

    end_profiling

    # rebooting has to be the last thing we do, no exceptions.

    Chef::Platform::Rebooter.reboot_if_needed!(node)
  rescue Exception => run_error
    # CHEF-3336: Send the error first in case something goes wrong below and we don't know why

    Chef::Log.debug("Re-raising exception: #{run_error.class} - #{run_error.message}\n#{run_error.backtrace.join("\n  ")}")
    # If we failed really early, we may not have a run_status yet. Too early for these to be of much use.

    if run_status
      run_status.stop_clock
      run_status.exception = run_error
      run_failed
    end
    events.run_failed(run_error)
  ensure
    Chef::RequestID.instance.reset_request_id
    request_id = nil
    @run_status = nil
    run_context = nil
    runlock.release
  end

  # Raise audit, converge, and other errors here so that we exit

  # with the proper exit status code and everything gets raised

  # as a RunFailedWrappingError

  if run_error || converge_error || audit_error
    error = if Chef::Config[:audit_mode] == :disabled
              run_error || converge_error
            else
              e = if run_error == converge_error
                    Chef::Exceptions::RunFailedWrappingError.new(converge_error, audit_error)
                  else
                    Chef::Exceptions::RunFailedWrappingError.new(run_error, converge_error, audit_error)
                  end
              e.fill_backtrace
              e
            end

    Chef::Application.debug_stacktrace(error)
    raise error
  end

  true
end

#run_audits(run_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the audit phase.

Triggers the audit_phase_start, audit_phase_complete and audit_phase_failed events.

Parameters:

  • run_context

    The run context.

Returns:

  • Any thrown exceptions. ‘nil` if successful.

See Also:

  • Audit::Runner#run
  • EventDispatch#audit_phase_start
  • EventDispatch#audit_phase_complete
  • EventDispatch#audit_phase_failed


731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/chef/client.rb', line 731

def run_audits(run_context)
  begin
    events.audit_phase_start(run_status)
    Chef::Log.info("Starting audit phase")
    auditor = Chef::Audit::Runner.new(run_context)
    auditor.run
    if auditor.failed?
      audit_exception = Chef::Exceptions::AuditsFailed.new(auditor.num_failed, auditor.num_total)
      @events.audit_phase_failed(audit_exception, Chef::Audit::Logger.read_buffer)
    else
      @events.audit_phase_complete(Chef::Audit::Logger.read_buffer)
    end
  rescue Exception => e
    Chef::Log.error("Audit phase failed with error message: #{e.message}")
    @events.audit_phase_failed(e, Chef::Audit::Logger.read_buffer)
    audit_exception = e
  end
  audit_exception
end

#run_completed_successfullyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Callback to fire notifications that the run completed successfully



436
437
438
439
440
441
# File 'lib/chef/client.rb', line 436

def run_completed_successfully
  success_handlers = self.class.run_completed_successfully_notifications
  success_handlers.each do |notification|
    notification.call(run_status)
  end
end

#run_failedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Callback to fire notifications that the Chef run failed



448
449
450
451
452
453
# File 'lib/chef/client.rb', line 448

def run_failed
  failure_handlers = self.class.run_failed_notifications
  failure_handlers.each do |notification|
    notification.call(run_status)
  end
end

#run_ohaiObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run ohai plugins. Runs all ohai plugins unless minimal_ohai is specified.

Sends the ohai_completed event when finished.

See Also:

  • EventDispatcher#
  • Chef::Config#minimal_ohai


557
558
559
560
561
# File 'lib/chef/client.rb', line 557

def run_ohai
  filter = Chef::Config[:minimal_ohai] ? %w{fqdn machinename hostname platform platform_version os os_version} : nil
  ohai.all_plugins(filter)
  events.ohai_completed(node)
end

#run_startedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Callback to fire notifications that the Chef run is starting



424
425
426
427
428
429
# File 'lib/chef/client.rb', line 424

def run_started
  self.class.run_start_notifications.each do |notification|
    notification.call(run_status)
  end
  events.run_started(run_status)
end

#save_updated_nodeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Save the updated node to Chef.

Does not save if we are in solo mode or using override_runlist.

See Also:



536
537
538
539
540
541
542
543
544
545
# File 'lib/chef/client.rb', line 536

def save_updated_node
  if Chef::Config[:solo]
    # nothing to do

  elsif policy_builder.temporary_policy?
    Chef::Log.warn("Skipping final node save because override_runlist was given")
  else
    Chef::Log.debug("Saving the current state of node #{node_name}")
    node.save
  end
end

#setup_run_contextObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets up the run context.

Returns:

  • The newly set up run context

See Also:

  • PolicyBuilder#setup_run_context


508
509
510
511
512
513
# File 'lib/chef/client.rb', line 508

def setup_run_context
  run_context = policy_builder.setup_run_context(specific_recipes)
  assert_cookbook_path_not_empty(run_context)
  run_status.run_context = run_context
  run_context
end

#sync_cookbooksObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sync cookbooks to local cache.

TODO this appears to be unused.

See Also:

  • PolicyBuilder#sync_cookbooks


496
497
498
# File 'lib/chef/client.rb', line 496

def sync_cookbooks
  policy_builder.sync_cookbooks
end