Table of Contents
The following cookbook design conventions are used by the v12.11 and v13.5 LTS ServerTemplates published by RightScale.
Before you start to create or customize any of these Chef-based ServerTemplates, it's important to have a solid understanding of how RightScale architected its library of cookbooks and ServerTemplates, as well as understand the reasons why RightScale uses certain cookbook design patterns and conventions. It's strongly recommended that you follow these same design conventions in your own custom cookbooks and recipes if you want to use them in ServerTemplates.
A reusable design pattern is a common coding convention that allows you to build more efficient and flexible code that's easier to share and manage. Instead of creating a single self-contained script that may include the same sections of code that are repeated in other scripts, you can define smaller pieces of code that are accessible and reusable across an entire codebase.
The first step is to understand the problem that we're trying to solve by following certain design patterns. One of the great features of Chef is that it's an example of a loosely coupled configuration system, which allows for extensibility in software design because one design component can reference and use another design component even if it changes over time. However, when you increase flexibility you also potentially increase complexity. Therefore, it's important to establish a set of best practices by following certain design patterns to encourage code consistency and make your cookbooks easier to develop and troubleshoot.
In the RightScale cookbooks, resource calls in recipes can be calls to built-in resources, lightweight resources, or definitions.
Typically, cookbooks depend on other cookbooks for resources, providers, and definitions. If a dependency is not explicitly specified in a cookbook's metadata (metadata.rb), its recipes may load without the cookbooks they depend on and will fail to execute. In addition, there are also resources that are set up in default recipes from other cookbooks. When developing or customizing a ServerTemplate, it's important to list all of the boot scripts in the correct order to ensure that any cookbook dependencies are resolved before a recipe that depends on those other resources is executed.
There are two types of cookbook dependencies.
More information about resolving cookbook dependencies is described below.
Definitions are often used for common sequences of resources in Chef recipes that are used in multiple recipes but do not warrant a separate recipe. For example, the 'db::do_primary_backup' and 'db::do_secondary_backup' recipes use the 'db_do_backup' definition that uses a set of resources from the 'db' and 'block_device' cookbooks to perform a database backup.
Important! RightScale Definitions are used in RightScale's v12 and v13 ServerTemplate releases. See ServerTemplates.
In addition to housing reusable recipe snippets of code that are used within a cookbook, we also use definitions as external methods that other cookbooks can call. For example, the 'rightscale_logrotate_app' definition allows other cookbooks to add their logrotate configurations while deferring details of logrotate to the 'rightscale' cookbook.
Since definitions can be used in recipes located in different cookbooks, it's important to use a naming convention so you can easily locate a definition's code. In the RightScale cookbooks, the location of a definition can be determined by its name. The cookbook where the definition can be found is used as a prefix in its name. For example, the 'rightscale_marker' definition is defined in the 'rightscale' cookbook and the 'db_do_backup' definition is defined in the 'db' cookbook.
All of the recipes in the RightScale cookbooks begin and end with a call to the 'rightscale_marker' definition, which is defined in the 'rightscale' cookbook. It is used for better readability and debugging of the logs. When a Chef runlist is executed, check the audit entries. Recipes that use the 'rightscale_marker' definition print log messages with the cookbook and recipe name in the runlist.
Important!
If you want to use the 'rightscale_marker' definition in your own recipes, you must include the 'rightscale' cookbook as a dependency in your cookbook's metadata.
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.