百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

chef-client

> 开发工具
开源

Chef 客户端烹饪书的开发仓库

172 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Chef 客户端烹饪书的开发仓库

Chef Client Cookbook

This cookbook is used to configure a system to run the Chef Infra Client.

Deprecation

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:

  • chef_client_config
  • chef_handler
  • chef_client_trusted_certificate
  • chef_client_cron
  • chef_client_systemd_timer
  • chef_client_scheduled_task
  • chef_client_launchd

What about older Chef Infra Client Releases

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.

The new resources are missing x, y, or z

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.

Requirements

Platforms

  • AIX 6+
  • Clear Linux
  • Debian
  • Fedora
  • FreeBSD
  • macOS
  • openSUSE
  • SLES 12+
  • RHEL
  • Solaris 10+
  • Ubuntu
  • Windows

Chef

  • Chef 13.0+

Cookbooks

  • cron 2.0+
  • logrotate 1.9.0+

See USAGE.

Resources

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.

chef_client_scheduled_task

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.

Actions

  • :add
  • :remove

Properties

  • user - 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 user
  • frequency - 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-client
  • task_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'

chef_client_cron

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.

Actions

  • :add
  • :remove

Properties

  • user - 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 macOS
  • append_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-client

chef_client_trusted_certificate

The 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.

Actions

  • :add
  • :remove

Properties

  • cert_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 file

Examples

ruby
chef_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):

ruby
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 true

The 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.

ruby
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.*"
    }
  }
)

Special Behavior

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:

  • the audit_mode, log_level, and ssl_verify_mode attributes are converted to symbols. The attribute need not include an initial colon. For example:
ruby
default_attributes(
  "chef_client" => {
    "config" => {
      "ssl_verify_mode" => ":verify_peer",
      "log_level" => "debug"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

ruby
ssl_verify_mode :verify_peer
log_level :debug
  • the log_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,
ruby
default_attributes(
  "chef_client" => {
    "config" => {
      "log_location" => "STDOUT"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

ruby
log_location STDOUT

and

ruby
default_attributes(
  "chef_client" => {
    "config" => {
      "log_location" => ":syslog"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

ruby
log_location :syslog

The strings "syslog" and "win_evt" will become the symbols :syslog and :win_evt regardless of whether they have an initial colon.

Configuration Includes

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:

ruby
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:

ruby
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:

ruby
log_location Chef::Log::WinEvt.new

Requiring Gems

Use 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:

ruby
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:

ruby
["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
end

Start, Report, Exception Handlers

To dynamically render configuration for Start, Report, or Exce

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubychefchef-clientcookbookhacktoberfest

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具