Development repository for Chef Client cookbook
This cookbook is used to configure a system to run the Chef Infra Client.
This cookbook is no longer under active maintenance. The functionality previously provided here is now built into Chef Infra Client itself making it easier to configure Chef Infra Client without the need for external dependencies.
See these built-in resources for managing client.rb configuration and setting up Chef Infra Client to run on a schedule:
If you're using an Infra Client release before the above resources shipped, you can keep using this cookbook without issue. Just keep in mind that at some point in the future changes to Chef Infra Client may cause this cookbook to stop working. We believe the built-in resoures offer a more powerful configuration options for users. The approach offered by these resources also align with our own best practices and we'd highly suggest moving towards those resources for configuring your Chef Infra Client.
If there's af feature missing from the new resources please do let us know at https://github.com/chef/chef/issues. We will not be replicating all functionality of this cookbook, but we are interested in hearing what the community needs to manage their systems.
See USAGE.
The chef-client cookbook provides several resources for setting up Chef Infra Client to run on a schedule. When possible these resources should be used instead of the legacy attributes / recipes as these same resources will be included in Chef Infra Client 16+ out of the box.
The chef_client_scheduled_task resource setups up Chef Infra Client to run as a scheduled task on Windows. You can use this resource directly in any of your own recipes. Using this resource to configure Chef Infra Client running as a scheduled task allows you to control where you store the user credentials instead of storing them as node attributes. This is useful if you want to store these credentials in an encrypted databag or other secrets store.
:add:removeuser - The username to run the task as. default: 'System'password The password of the user to run the task as if not using the System userfrequency - Frequency with which to run the task (e.g., 'hourly', 'daily', etc.) Default is 'minute'frequency_modifier Numeric value to go with the scheduled task frequency - default: '30'start_time The start time for the task in HH:mm format (ex: 14:00). If the frequency is minute default start time will be Time.now plus the frequency_modifier number of minutes.start_date - The start date for the task in m:d:Y format (ex: 12/17/2017). nil by default and isn't necessary if you're running a regular interval.splay - A random number of seconds between 0 and X to add to interval. default: '300'config_directory - The path to the Chef config directory. default: 'C:/chef'log_file_name - The name of the log file. default: 'client.log'log_directory - The path to the Chef log directory. default: 'CONFIG_DIRECTORY/log'chef_binary_path - The path to the chef-client binary. default: 'C:/opscode/chef/bin/chef-client'daemon_options - An optional array of extra options to pass to the chef-clienttask_name - The name of the scheduled task. This allows for multiple chef_client_scheduled_task resources when it is used directly like in a wrapper cookbook. default: 'chef-client'The chef_client_cron resource sets up Chef Infra Client to run as a cron job using a cron.d configuration file on Linux hosts or a job in /etc/crontab for other Unix operating systems. You can use this resource directly in any of your own recipes.
:add:removeuser - The username to run the task as. default: 'root'minute - The minute that Chef Infra Client will run as a cron task. default: '0,30' (every 30 minutes)hour - The hour that Chef Infra Client will run as a cron task. default: '*'day - The day that Chef Infra Client will run as a cron task. default: '*'month - The month that Chef Infra Client will run as a cron task. default: '*'weekday - The weekday that Chef Infra Client will run as a cron task. default: '*'comment - A comment to add to the cron file.mailto - The e-mail address to e-mail any cron task failures to.job_name - The name of the cron task to create. This allows you to have schedules with different options if necessary. default: 'chef-client'splay - A random number of seconds between 0 and X to add to interval. default: '300'environment - A hash of environment variables to pass to chef-client's execution (e.g. SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt chef-client)config_directory - The path to the Chef config directory. default: '/etc/chef/'log_file_name - The name of the log file. default: 'client.log'log_directory - The path to the Chef log directory. default: '/var/log/chef' on *nix or '/Library/Logs/Chef' on macOSappend_log_file - Whether to append to the log. Default: true chef-client output.chef_binary_path - The path to the chef-client binary. default: '/opt/chef/bin/chef-client'daemon_options - An optional array of extra command line options to pass to the chef-clientThe chef_client_trusted_certificate allows you to add a certificate to Chef Infra Client's set of trusted certificates. This is helpful when adding internal certificates for systems that the Chef Infra Client will later need to communicate with using SSL. You can use this resource directly in any of your own recipes.
:add:removecert_name - The name on disk for the cert file. If not specified the resource name will be used (and .pem appended if necessary)certificate - The text content of the certificate filechef_client_trusted_certificate 'self-signed.badssl.com' do
certificate {
"config" => {
"ssl_verify_mode" => ":verify_peer",
"client_fork" => true
}
}
)will render the following configuration (/etc/chef/client.rb):
chef_server_url "https://api.chef.io/organizations/MYORG"
validation_client_name "MYORG-validator"
ssl_verify_mode :verify_peer
node_name "config-ubuntu-1204"
client_fork trueThe chef_server_url, node_name and validation_client_name are set by default in the attributes file from Chef::Config. They are presumed to come from the knife bootstrap command when setting up a new node for Chef. To set the node name to the default value (the node['fqdn'] attribute), it can be set false. Be careful when setting this or the Server URL, as those values may already exist.
As another example, to set HTTP proxy configuration settings. By default Chef will not use a proxy.
default_attributes(
"chef_client" => {
"config" => {
"http_proxy" => "http://proxy.mycorp.com:3128",
"https_proxy" => "http://proxy.mycorp.com:3128",
"http_proxy_user" => "my_username",
"http_proxy_pass" => "Awe_some_Pass_Word!",
"no_proxy" => "*.vmware.com,10.*"
}
}
)Because attributes are strings and the /etc/chef/client.rb can use settings that are not string, such as symbols, some configuration attributes have resulting lines with special behavior:
audit_mode, log_level, and ssl_verify_mode attributes are converted to symbols. The attribute need not include an initial colon. For example:default_attributes(
"chef_client" => {
"config" => {
"ssl_verify_mode" => ":verify_peer",
"log_level" => "debug"
}
}
)will render the following configuration (/etc/chef/client.rb):
ssl_verify_mode :verify_peer
log_level :debuglog_level setting can be either a string representing a file path or one of the symbols STDOUT, STDERR, :syslog, and :win_evt. If the log_level attribute is a string suggestive of one of these symbols, the resulting configuration line will use the symbol. For example,default_attributes(
"chef_client" => {
"config" => {
"log_location" => "STDOUT"
}
}
)will render the following configuration (/etc/chef/client.rb):
log_location STDOUTand
default_attributes(
"chef_client" => {
"config" => {
"log_location" => ":syslog"
}
}
)will render the following configuration (/etc/chef/client.rb):
log_location :syslogThe strings "syslog" and "win_evt" will become the symbols :syslog and :win_evt regardless of whether they have an initial colon.
The /etc/chef/client.rb file will include all the configuration files in /etc/chef/client.d/*.rb. To create custom configuration, simply render a file resource with file (and the content parameter), template, remote_file, or cookbook_file. For example, in your own cookbook that requires custom Chef client configuration, create the following cookbook_file resource:
chef_gem 'syslog-logger'
cookbook_file "/etc/chef/client.d/myconfig.rb" do
source "myconfig.rb"
mode '0644'
notifies :create, "ruby_block[reload_client_config]"
end
include_recipe 'chef-client::config'Then create files/default/myconfig.rb with the configuration content you want. For example, if you wish to create a configuration to log to syslog:
require 'syslog-logger'
require 'syslog'
Logger::Syslog.class_eval do
attr_accessor :sync, :formatter
end
log_location Chef::Log::Syslog.new('chef-client', ::Syslog::LOG_DAEMON)On Windows:
log_location Chef::Log::WinEvt.newUse the load_gems attribute to install gems that need to be required in the client.rb. This attribute should be a hash. The gem will also be installed with chef_gem. For example, suppose we want to use a Chef Handler Gem, chef-handler-updated-resources, which is used in the next heading. Set the attributes, e.g., in a role:
default_attributes(
"chef_client" => {
"load_gems" => {
"chef-handler-updated-resources" => {
"require_name" => "chef/handler/updated_resources",
"version" => "0.1"
}
}
}
)Each key in load_gems is the name of a gem. Each gem hash can have two keys, the require_name which is the string that will be require'd in /etc/chef/client.rb, and version which is the version of the gem to install. If the version is not specified, the latest version will be installed.
The above example will render the following in /etc/chef/client.rb:
["chef/handler/updated_resources"].each do |lib|
begin
require lib
rescue LoadError
Chef::Log.warn "Failed to load #{lib}. This should be resolved after a chef run."
end
endTo dynamically render configuration for Start, Report, or Exce
No open issues yet, or sync has not completed.