Overview
Introduction
Chef recipes are plain Ruby, which is powerful but means there's no fixed template to fill in, just resource blocks with a type, a name, and an action, written by hand every time.
This tool generates a recipe.rb from repeatable resource rows, each rendered as a correctly formatted Chef resource block, including the `node[...]` attribute lookup pattern when you need a resource's name to come from cookbook attributes rather than a hardcoded string.
What Is Chef Recipe Generator?
A Chef recipe generator supporting the four most common resource types, package, service, template, and file, each configured with a name (or attribute path), an action, and rendered as a valid Ruby DSL block.
When a row specifies an attribute path (e.g. `nginx.package_name`), the resource's identifier renders as a nested `node['nginx']['package_name']` lookup instead of a plain string literal.
How Chef Recipe Generator Works
For each resource row, you choose a resource type, a name (used as the literal resource identifier unless an attribute path is given), and an action.
The tool renders each as `<type> <name_expression> do ... action :<action> end`, adding a `source` line automatically for template resources, and converts any provided attribute path into Chef's bracketed `node['a']['b']` lookup syntax.
When To Use Chef Recipe Generator
Use it when scaffolding a new cookbook's recipe and you want correctly formatted resource blocks for the common package/service/template/file pattern.
It's also useful for demonstrating the difference between hardcoding a resource name and pulling it from `node[...]` attributes, a common Chef convention for configurable cookbooks.
Often used alongside Ansible Playbook Generator and Puppet Manifest Generator.
Features
Advantages
- Correctly renders Chef's `node['a']['b']` bracketed attribute lookup syntax from a simple dot-path input, rather than requiring you to type the brackets and quotes by hand.
- Covers the four resource types that make up the overwhelming majority of real-world recipes.
- Validates that every resource has a valid Ruby-symbol-safe action before generating output.
Limitations
- Doesn't support Chef's more advanced resource properties (guards like `only_if`/`not_if`, `notifies`/`subscribes` between resources), only the name and action.
- The template resource's auto-derived `source` filename is a reasonable guess, not guaranteed to match an actual file in your cookbook's `templates/` directory.
Examples
Best Practices & Notes
Best Practices
- Prefer `node[...]` attribute references over hardcoded names for anything that might differ by platform or environment (package names often do between Debian and RHEL families).
- Use `notifies`/`subscribes` (added by hand after generation) instead of separate independent resources when one resource's change should trigger another, Chef's equivalent of Ansible's handler pattern.
- Keep one resource type's concerns together (e.g. all package installs before the services that depend on them) for readability, even though Chef resolves dependencies via the resource collection, not file order alone.
Developer Notes
Attribute path conversion splits the input on `.` or `/` and joins each segment as `['segment']`, matching Chef's real attribute-access syntax (`node['nginx']['package_name']`), which under the hood is Chef::Node::ImmutableMash's bracket accessor; actions are validated against a permissive `^[a-z_]+$` pattern rather than a fixed enum, since Chef resources define their own valid action symbols per resource type rather than sharing one global list.
Chef Recipe Generator Use Cases
- Scaffolding a new cookbook recipe's package/service/template/file resources
- Demonstrating Chef's node attribute lookup pattern for configurable resource names
- Producing a consistent recipe structure across a team's cookbooks
Common Mistakes
- Hardcoding a package name that differs across the platforms the cookbook targets, instead of pulling it from a platform-aware attribute.
- Forgetting that a generated template resource's `source` filename is a placeholder guess, not an existing file, until you create it in templates/.
Tips
- Use the Ansible Playbook Generator or Puppet Manifest Generator instead if your infrastructure targets one of those configuration management tools rather than Chef.