Warning
config.rb file is a replacement for the knife.rb file. The config.rb file has identical settings and behavior to the knife.rb file. Chef Infra Client looks first for the presence of the config.rb file and if it is not found, then looks for the knife.rb file. A config.rb file is used to specify configuration details for knife.
A config.rb file:
~/.chef/config.rb (macOS and Linux platforms) or c:\Users\username\.chef\config.rb (Microsoft Windows platform), use the --config option from the command line to change this locationconfig.rb file exists at the default path or the path specified by the --config optionNote
config.rb file is located at %HOMEDRIVE%:%HOMEPATH%\.chef (e.g. c:\Users\<username>\.chef). This configuration file has the following settings:
bootstrap_templatechef_server_urlchef_server_url 'https://localhost/organizations/ORG_NAME'
Note
knife exec with the --server-url flag to set chef_server_url to https://localhost/. chef_zero.enabledlocal_mode to be set to true. Default value: false. For example: chef_zero.enabled true
chef_zero[:port]8889. For example: chef_zero[:port] 8889
client_d_dirclient_key/etc/chef/client.pem. For example: client_key '/etc/chef/client.pem'
cookbook_copyrightcookbook_emailcookbook_licenseapachev2, gplv2, gplv3, mit, or none (default). This option places the appropriate license notice in the pre-created files: Apache v2.0 (for apachev2), GPL v2 (for gplv2), GPL v3 (for gplv3), MIT (for mit), or license 'Proprietary - All Rights Reserved (for none). Be aware of the licenses for files inside of a cookbook and be sure to follow any restrictions they describe.cookbook_pathcookbook_path [
'/var/chef/cookbooks',
'/var/chef/site-cookbooks'
]
data_bag_encrypt_version1 or 2. When all of the machines in an organization are running Chef Client 11.6 (or higher), it is recommended that this value be set to 2. For example: data_bag_encrypt_version 2
fipstrue to enable FIPS-validated security. The following operating systems are supported:
local_modelocal_mode true
node_nameThe name of the node. This may be a username with permission to authenticate to the Chef Infra Server or it may be the name of the machine from which knife is run. For example:
node_name 'user_name'
or:
node_name 'machine_name'
no_proxyA comma-separated list of URLs that do not need a proxy. Default value: nil. For example:
no_proxy 'localhost, 10.0.1.35, *.example.com, *.dev.example.com'
ssh_agent_signingssh-agent to authenticate. When using this option, specify the location of the public key in client_key. Default value: false. Ensure the public key is in PKCS#1 format. You can convert an OpenSSH public key using ssh-keygen. For example: ssh-keygen -f key.pub -e -m pem > key.pem
ssh_timeoutssl_verify_mode:verify_none to do no validation of SSL certificates.:verify_peer to do validation of all SSL certificates, including the Chef Infra Server connections, S3 connections, and any HTTPS remote_file resource URLs used in a Chef Infra Client run. This is the recommended setting.Depending on how OpenSSL is configured, the ssl_ca_path may need to be specified. Default value: :verify_peer.
tmux_splitSplit the Tmux window. Default value: false.
validation_client_nameThe name of the chef-validator key that is used by Chef Infra Client to access the Chef Infra Server during the initial Chef Infra Client run when not using validatorless bootstrapping. For example:
validation_client_name 'chef-validator'
validation_keyThe location of the file that contains the key used when a Chef Infra Client is registered with a Chef Infra Server. A validation key is signed using the validation_client_name for authentication. Default value: /etc/chef/validation.pem. For example:
validation_key '/etc/chef/validation.pem'
verify_api_certtrue, Chef Infra Client always verifies the SSL certificate. When false. Chef Infra Client uses the value of ssl_verify_mode to determine if the SSL certificate requires verification. Default value: false.versioned_cookbooksfalse to hide cookbook versions: cookbooks/apache. Set to true to show cookbook versions: cookbooks/apache-1.0.0 and/or cookbooks/apache-1.0.1. When this setting is true, knife download downloads ALL cookbook versions, which can be useful if a full-fidelity backup of data on the Chef Infra Server is required. For example: versioned_cookbooks true
config_log_levellog_level in the client.rb file of the node being bootstrapped. Possible values are :debug, :info, :warn, :error and :fatal. For example: config_log_level :debug
config_log_locationlog_location in the client.rb file of the node being bootstrapped. Possible values are /path/to/log_location, STDOUT, STDERR, :win_evt and :syslog. For example: config_log_location "/path/to/log_location" # Please make sure that the path exists
In certain situations the proxy used by the Chef Infra Server requires authentication. In this situation, three settings must be added to the configuration file. Which settings to add depends on the protocol used to access the Chef Infra Server: HTTP or HTTPS.
If the Chef Infra Server is configured to use HTTP, add the following settings:
http_proxynil. For example: http_proxy 'http://proxy.example.com:3128'
http_proxy_usernil.http_proxy_passnil.https_proxynil.https_proxy_usernil.https_proxy_passnil.no_proxynil.Chef Infra Client supports reading multiple configuration files by putting them inside a .d configuration directory. For example: /etc/chef/client.d. All files that end in .rb in the .d directory are loaded; other non-.rb files are ignored.
.d directories may exist in any location where the client.rb, config.rb, or solo.rb files are present, such as:
/etc/chef/client.d/etc/chef/config.d~/chef/solo.d(There is no support for a knife.d directory; use config.d instead.)
For example, when using knife, the following configuration files would be loaded:
~/.chef/config.rb~/.chef/config.d/company_settings.rb~/.chef/config.d/ec2_configuration.rb~/.chef/config.d/old_settings.rb.bakThe old_settings.rb.bak file is ignored because it’s not a configuration file. The config.rb, company_settings.rb, and ec2_configuration files are merged together as if they are a single configuration file.
Note
If multiple configuration files exists in a .d directory, ensure that the same setting has the same value in all files.
In addition to the default settings in a config.rb file, there are other subcommand-specific settings that can be added:
config.rb fileA value passed via the command line overrides a value in the config.rb file; a value in a config.rb file overrides a default value. Before adding any settings to the config.rb file:
Also note that:
config.rb fileTo add settings to the config.rb file, use the following syntax:
knife[:setting_name] = value
where value may require quotation marks (' ‘) if that value is a string. For example:
knife[:ssh_port] = 22
knife[:bootstrap_template] = 'ubuntu14.04-gems'
knife[:bootstrap_version] = ''
knife[:bootstrap_proxy] = ''
Some of the optional config.rb settings are used often, such as the template file used in a bootstrap operation. The frequency of use of any option varies from organization to organization, so even though the following settings are often added to a config.rb file, they may not be the right settings to add for every organization:
knife[:bootstrap_proxy]knife[:bootstrap_template]knife[:bootstrap_version]knife[:editor]knife[:ssh_gateway]knife[:ssh_port]Other SSH-related settings that are sometimes helpful when added to the config.rb file:
knife[:forward_agent]knife[:ssh_attribute]knife[:ssh_password]knife[:ssh_user]Some organizations choose to have all data bags use the same secret and secret file, rather than have a unique secret and secret file for each data bag. To use the same secret and secret file for all data bags, add the following to config.rb:
knife[:secret]knife[:secret_file]Some settings are better left to Ohai, which gets the value at the start of a Chef Infra Client run:
knife[:server_name]node_name. Recommended configuration is to allow Ohai to collect this value during each Chef Infra Client run.node_nameknife[:server_name]. Recommended configuration is to allow Ohai to collect this value during each Chef Infra Client run.Warning
config.rb file. Many of these optional settings should not be added to the config.rb file. The reasons for not adding them can vary. For example, using --yes as a default in the config.rb file causes knife to always assume that “Y” is the response to any prompt, which may lead to undesirable outcomes. Other settings, such as --hide-healthy(used only with the knife status subcommand) or --bare-directories (used only with the knife list subcommand) probably aren’t used often enough (and in the same exact way) to justify adding them to the config.rb file. In general, if the optional settings are not listed on the main config.rbtopic, then add settings only after careful consideration. Do not use optional settings in a production environment until after the setting’s performance has been validated in a safe testing environment.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/config_rb/