Configuring Chef Provisioner
1. Setting Cookbooks Path
| Option | Values | Description |
|---|---|---|
| cookbooks_path | string or array |
Path(s) to the cookbooks directory. Can be a single path or an array of paths. |
Example: Setting cookbooks path
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
end
Example: Setting multiple cookbooks paths
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
end
2. Configuring Roles Path
| Option | Values | Description |
|---|---|---|
| chef_roles_path | string or array |
Path(s) to the directory containing Chef roles. Can be a single string or an array of paths. |
Note: The roles path is used by the Chef provisioner to locate role definitions when applying configurations.
3. Using Data Bags
| Property | Description | Example |
|---|---|---|
| data_bag_name | Name of the data bag to use | "users" |
| data_bag_item | Name of the data bag item to retrieve | "admin" |
Example: Accessing Data Bag in Recipe
user_data = data_bag_item("users", "admin")
username = user_data["username"]
password = user_data["password"]
Note: Data bags must be created in the
data_bags directory of your Chef repository.
Warning: Sensitive data in data bags should be encrypted using Chef's built-in encryption or external tools.
4. Setting Run List
| Property | Description | Example |
|---|---|---|
| run_list | Defines the list of recipes and roles to be executed during the Chef run. Can include recipes, roles, or a combination. | ["recipe[nginx]", "role[webserver]"] |
Example: Setting Run List in Vagrantfile
vagrantfile_content = <<~EOF
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provision :chef_solo do |chef|
chef.run_list = [
"recipe[nginx]",
"role[webserver]"
]
end
end
EOF
5. Configuring Chef JSON
| Property | Description | Values |
|---|---|---|
| json | JSON configuration to pass to Chef | Object or string |
| json_file | Path to a JSON file containing Chef configuration | String |
Example: Setting Chef JSON Configuration
config.vm.provision :chef_solo do |chef|
chef.json = {
"nginx" => {
"port" => 8080,
"config" => "/etc/nginx"
}
}
end
Example: Using a JSON File
config.vm.provision :chef_solo do |chef|
chef.json_file = "./chef/config.json"
end
6. Using Environments
| Property | Description | Default |
|---|---|---|
| environments_path | Path to the directory containing environment definitions. | environments |
| environment | Name of the environment to use for provisioning. | production |
Example: Setting Environment in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.omnibus.chef_version = "latest"
config.vm.provision :chef_solo do |chef|
chef.environments_path = "./environments"
chef.environment = "staging"
end
end
Note: Ensure that the environment file exists in the specified
environments_path.7. Setting Chef Version
| Option | Values | Notes |
|---|---|---|
| chef.version | "18.4.0" |
Latest stable Chef version as of 2026 |
| chef.version | "17.10.1" |
Previous stable Chef version |
| chef.version | "16.2.70" |
Legacy Chef version (deprecated) |
Example: Setting Chef Version in Vagrantfile
vagrantfile_content = <<~EOF
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provision :chef_solo do |chef|
chef.version = "18.4.0"
end
end
EOF
Note: Setting the Chef version ensures consistent provisioning across all environments.
8. Configuring Chef Log Level
| Option | Values | Description |
|---|---|---|
| log_level | debug, info, warn, error, fatal |
Sets the log level for Chef runs. Default is info. |
Example: Setting Log Level in Vagrantfile
vagrantfile_content = <<~EOF
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provision :chef_solo do |chef|
chef.log_level = "debug"
end
end
EOF
9. Using Chef Zero vs Solo
| Feature | Chef Zero | Chef Solo |
|---|---|---|
| Mode of Operation | chef_zero |
chef_solo |
| Configuration | Uses local Chef Infra Client with embedded Chef Zero server | Uses local Chef Infra Client without embedded server |
| Network Access | Does not require network access to Chef Server | Does not require network access to Chef Server |
| Cookbook Source | Local cookbooks or remote via Berksfile | Local cookbooks or remote via Berksfile |
| Dependency Management | Supports Berkshelf and Policyfiles | Supports Berkshelf only |
| Performance | Optimized for local development and testing | Optimized for production environments |
| Use Case | Development, testing, and CI environments | Production deployments or environments with limited network access |
Example: Chef Zero Configuration
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.environment = "development"
chef.json = {
"nginx" => {
"port" => 8080
}
}
end
Example: Chef Solo Configuration
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.environment = "development"
chef.json = {
"nginx" => {
"port" => 8080
}
}
end
Chef Zero vs Solo Summary
- Chef Zero is ideal for local development and testing, offering faster execution and better integration with modern Chef workflows.
- Chef Solo is more suitable for production environments or systems with restricted network access.
- Both modes support local cookbooks and external cookbook sources via Berkshelf or Policyfiles.
10. Setting Custom Config
| Option | Values | Description |
|---|---|---|
| chef_config | string |
Path to a custom Chef configuration file (e.g., client.rb) |
| chef_server_url | string |
URL of the Chef server to connect to |
| node_name | string |
Name of the Chef node (default: Vagrant machine name) |
| validation_client_name | string |
Name of the validation client used to authenticate with Chef server |
| validation_key_path | string |
Path to the validation key file (e.g., validation.pem) |
| client_key_path | string |
Path to the client key file (e.g., client.pem) |
Example: Custom Chef Config
config.vm.provision :chef_solo do |chef|
chef.chef_config = "/path/to/chef/client.rb"
chef.chef_server_url = "https://api.chef.io/organizations/myorg"
chef.node_name = "vagrant-node"
chef.validation_client_name = "myorg-validator"
chef.validation_key_path = "/path/to/chef/validation.pem"
chef.client_key_path = "/path/to/chef/client.pem"
end