Class | Chef::Client
In: | lib/chef/client.rb
Parent: | Object

## Chef::Client

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

### Methods

build_node clear_notifications converge enforce_path_sanity new node_name register run run_completed_successfully run_completed_successfully_notifications run_failed run_failed_notifications run_ohai run_start_notifications run_started save_updated_node setup_run_context sync_cookbooks when_run_completes_successfully when_run_fails when_run_starts

### Constants

SANE_PATHS | = | %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin]

### Attributes

json_attribs | [R] |
node | [RW] |
ohai | [RW] |
rest | [RW] |
run_status | [R] |
runner | [RW] |

### Public Class methods

clear_notifications()

Clears all notifications for client run status events. Primarily for testing purposes.

new(json_attribs=nil)

Creates a new Chef::Client.

run_completed_successfully_notifications()

The list of notifications to be run when the client run completes successfully.

run_failed_notifications()

The list of notifications to be run when the client run fails.

run_start_notifications()

The list of notifications to be run when the client run starts.

when_run_completes_successfully(&notification_block)

Add a notification for the ‘client run success’ event. The notification is provided as a block. The current Chef::RunStatus object will be passed to the notification_block when the event is triggered.

when_run_fails(&notification_block)

Add a notification for the ‘client run failed’ event. The notification is provided as a block. The current Chef::RunStatus is passed to the notification_block when the event is triggered.

when_run_starts(&notification_block)

Add a notification for the ‘client run started’ event. The notification is provided as a block. The current Chef::RunStatus object will be passed to the notification_block when the event is triggered.

### Public Instance methods

build_node()

Builds a new node object for this client. Starts with querying for the FQDN of the current host (unless it is supplied), then merges in the facts from Ohai.

### Returns

node<Chef::Node>: | Returns the created node object, also stored in @node

converge(run_context)

Converges the node.

### Returns

true: | Always returns true

enforce_path_sanity(env=ENV)
node_name()
register(client_name=node_name, config=Chef::Config)

### Returns

rest<Chef::REST>: | returns Chef::REST connection object

run()

Do a full run for this Chef::Client. Calls:

     * run_ohai - Collect information about the system
     * build_node - Get the last known state, merge with local changes
     * register - If not in solo mode, make sure the server knows about this client
     * sync_cookbooks - If not in solo mode, populate the local cache with the node's cookbooks
     * converge - Bring this system up to date

### Returns

true: | Always returns true.

run_completed_successfully()

Callback to fire notifications that the run completed successfully

run_failed()

Callback to fire notifications that the Chef run failed

run_ohai()
run_started()

Callback to fire notifications that the Chef run is starting

save_updated_node()
setup_run_context()

     Configures the Chef::Cookbook::FileVendor class to fetch file from the
     server or disk as appropriate, creates the run context for this run, and
     sanity checks the cookbook collection.

### Returns

     Chef::RunContext:: the run context for this run.

sync_cookbooks()

Sync_cookbooks eagerly loads all files except files and templates. It returns the cookbook_hash — the return result from /environments/#{node.chef_environment}/cookbook_versions, which we will use for our run_context.

### Returns

Hash: | The hash of cookbooks with download URLs as given by the server

[Validate]