OSChefInfra.003 explores how Chef Infra organizes reusable infrastructure configuration. A cookbook can contain recipes, node attribute defaults, and Embedded Ruby (ERB) templates. Together, those files describe desired settings and produce a configuration suited to a managed machine. The lesson uses fictional service settings and an isolated practice directory, without requiring production access or an operational Chef Infra Server.
The Chef Infra curriculum begins with OSChefInfra.001: Architecture and OSChefInfra.002: Resources and Recipes. Familiarity with OSBash.001: Shell Basics and OSBash.007: Safe Command-Line Arguments helps when working in a Linux sandbox. The current track is OSChefInfra, not the separate Chef esoteric programming language.
Learning objectives
- Locate
metadata.rb,attributes/,recipes/, andtemplates/inside a cookbook. - Define node defaults and read values through the Chef
nodeobject. - Pass recipe values into an ERB template using the
variablesproperty. - Explain how template resources manage the desired contents of a file.
- Distinguish ordinary Ruby/ERB checks from a real Chef Infra Client convergence run.
Progress Chef, “Using Attributes in Cookbook”, June 20, 2023. Official demonstration of cookbook attributes. Video source confirmed; player playback is assessed separately.
What belongs in a cookbook?
A cookbook packages a related set of configuration instructions. A recipe declares resources, metadata.rb identifies the cookbook and version, attributes/default.rb holds default settings, and templates/default/ contains ERB input files. The Chef Infra 19 cookbook guide documents the directory roles. A recipe must be selected by a run list or equivalent local-mode configuration before Chef Infra Client applies its resources.
opencert_lab/
├── metadata.rb
├── attributes/
│ └── default.rb
├── recipes/
│ └── default.rb
└── templates/
└── default/
└── settings.conf.erb
Node attributes and precedence
The practice cookbook defines three fictional values: a service label, port 8080, and an enabled flag set to false. Attributes are stored in the Chef node object and may come from cookbooks, policies, or automatic node discovery. Default attributes provide baseline values; higher-precedence settings can replace them according to Chef’s documented order. A default is not an immutable constant, and an attribute is not a secure place for plaintext credentials.
# attributes/default.rb
default['opencert_lab']['service'] = 'training-dashboard'
default['opencert_lab']['port'] = 8080
default['opencert_lab']['enabled'] = false
Chef documents the precedence rules in its attribute precedence reference. For a beginner exercise, keep one clearly named default rather than layering normal, override, force-default, and automatic values without understanding their consequences.

Use a template resource to render settings
The recipe declares a directory and a template resource. source 'settings.conf.erb' identifies the ERB file in the cookbook template folder; variables(...) passes service, port, and enabled values. The destination lives only in a temporary exercise directory. Running Chef would create or update files, so the lab belongs in a disposable VM or container, never an unreviewed production host.
# recipes/default.rb
lab_dir = '/tmp/opencert-chef-infra-003'
directory lab_dir do
mode '0755'
action :create
end
template "#{lab_dir}/settings.conf" do
source 'settings.conf.erb'
mode '0644'
variables(
service: node['opencert_lab']['service'],
port: node['opencert_lab']['port'],
enabled: node['opencert_lab']['enabled']
)
action :create
end
The template reads the values as @service, @port, and @enabled. ERB substitutes each expression into plain text. The expected example output is a fictional service label, port 8080, and enabled=false. The official template resource reference describes source, variables, permissions, and create/update behavior.
# templates/default/settings.conf.erb
# Educational Chef Infra settings. Do not use as a production configuration.
service=<%= @service %>
port=<%= @port %>
enabled=<%= @enabled %>
Progress Chef, “How to Set Up Chef Workstation, Create a Cookbook and Get Started with Compliance”. Official historical walkthrough covering cookbook creation and attributes. Check current product releases and licensing independently.
For independent reproduction, the complete Chef Infra practice cookbook and 20-check Ruby test runner are archived together. Run ruby tests/test_template.rb from the cookbook root to verify its standalone ERB behavior without executing Chef resources.
What was actually tested?
The metadata, attribute, recipe, and test files passed syntax validation under Ruby 3.3.8 using ruby -c. A standard Ruby ERB renderer produced the expected configuration, and 20 structural and rendering assertions passed. Those checks verify Ruby syntax, the presence of Chef resource declarations, variable references, and the generated text. Chef Infra Client was unavailable in the publication environment, so actual convergence, repeated idempotence, server compatibility, and privilege behavior have not been tested.
In a disposable Linux lab with Chef Workstation properly installed and licensed, administrators can create the cookbook under a configured cookbook path and run a controlled local-mode test. Before a real Chef run, review path ownership, permissions, resources, and any policy restrictions. Chef’s Workstation setup guide is the appropriate starting point.
Operational boundaries and knowledge check
- Where do default attribute declarations go? Commonly
attributes/default.rb. - Where is the ERB source stored? Under the cookbook’s
templates/hierarchy. - What passes recipe values to the template? The
variablesproperty. - Does a successful Ruby syntax test prove Chef converged? No; the Chef client must be exercised separately.
- Are node attributes suitable for private keys? No; use a dedicated secrets-management mechanism.
References and conclusion
- Progress Chef: About Cookbooks.
- Progress Chef: Attribute Precedence.
- Progress Chef: Template Resource.
- Progress Chef: About Templates.
- Progress Chef: Workstation Getting Started.
Cookbooks keep infrastructure definitions organized. Attributes hold customizable settings, recipes declare desired resources, and ERB templates turn data into configuration files. The boundaries between those layers help teams review changes, repeat deployments, and reduce manual errors. Test carefully before applying changes to real machines.
Editor’s Note: OSChefInfra.003 follows OSChefInfra.002 in the verified OpenCert rotation and is distinct from OSChef esoteric-language lessons. The 1200 × 630 cover is original anime-style editorial artwork depicting a fictional engineer. The genuine in-body Progress Chef graphic comes from the vendor’s product announcement. Both video sources were identified on the official Progress Chef channel; actual embedded playback is unverified. Twenty Ruby/ERB checks passed, but Chef Infra Client was not installed, so no convergence or idempotence claims are made. SmartChart was omitted because no relevant external numeric dataset exists for a comparison.

For mobile scanning, display the QR on another screen or use a compatible wallet’s saved-image scanner. Verify the payment destination and amount before authorizing payment.
We volunteer daily to ensure information on BitcoinVersus.Tech is Verifiably True. Optional contributions support independent research and technical education.
Educational examples are not production deployment instructions, security audit results, or proof of compliance. Run infrastructure automation only in authorized environments.

Leave a Reply