Chef DevOps Cookbook Development & Resource Management 1 — Questions and Answers
Question 1: What is the primary purpose of the `metadata.rb` file in a Chef cookbook?
- To store node attribute default values
- To define the cookbook name, version, dependencies, and other metadata (Correct answer)
- To list all recipe files included in the cookbook
- To configure the Chef Server connection settings
Correct answer: To define the cookbook name, version, dependencies, and other metadata
metadata.rb declares the cookbook's name, version, description, and dependency information used by Berkshelf and the Chef Server.
Question 2: Which directory within a Chef cookbook stores ERB template files used by the `template` resource?
- files/default/
- resources/
- templates/default/ (Correct answer)
- attributes/
Correct answer: templates/default/
The `templates/default/` directory holds ERB files that the `template` resource renders onto the node with variable substitution.
Question 3: Which command in Chef Workstation generates a new cookbook skeleton with the recommended directory structure?
- knife cookbook create <name>
- chef generate cookbook <name> (Correct answer)
- berkshelf init <name>
- chef init cookbook <name>
Correct answer: chef generate cookbook <name>
`chef generate cookbook <name>` is the modern Chef Workstation command that creates a cookbook with the correct directory layout, metadata.rb, and test files.
Question 4: What is the role of the `Berksfile` in a Chef cookbook?
- It defines the node run list for cookbook execution
- It specifies cookbook dependencies and their sources for Berkshelf to resolve (Correct answer)
- It stores encrypted secrets used by the cookbook at runtime
- It configures knife plugin settings for the cookbook
Correct answer: It specifies cookbook dependencies and their sources for Berkshelf to resolve
The Berksfile tells Berkshelf where to find and which versions of dependent cookbooks to download before uploading to the Chef Server.
Question 5: In a Chef attributes file, what is true about the `default` precedence level?
- It is the highest user-settable precedence that overrides role attributes
- It is the lowest precedence level, overridden by role, environment, and node attributes (Correct answer)
- It is an automatic precedence level set by Ohai at runtime
- It has the same precedence as attributes set with `node.normal`
Correct answer: It is the lowest precedence level, overridden by role, environment, and node attributes
`default` is the lowest cookbook attribute precedence, making it straightforward for operators to override via roles, environments, or node JSON.
Question 6: Which Chef resource renders a file on the node from an ERB template stored in the cookbook?
- cookbook_file
- file
- template (Correct answer)
- remote_file
Correct answer: template
The `template` resource reads an ERB file from `templates/default/`, substitutes node attribute variables, and writes the result to the node filesystem.
Question 7: Which Chef attribute precedence level is automatically populated by Ohai and takes priority over all others?
- force_override
- override
- automatic (Correct answer)
- normal
Correct answer: automatic
Automatic attributes are populated by Ohai during node check-in and cannot be overridden by any cookbook, role, or environment attribute.
What is the primary purpose of the `metadata.rb` file in a Chef cookbook?