InterviewSolution
| 1. |
How to create a custom resource in Chef? |
|
Answer» Custom RESOURCES in Chef are add on resources transported as a pat of cookbooks and used by Chef Client. These are reusable in the same way as pre-defined resources in Chef. Custom resources are kept as a separate Ruby FILE in the resources folder of a cookbook. For eg: Assume that we need to create a custom resource called “WEBSITE” that make use of in-built resources of Chef like file, package and service resources. Where
The website resource is NAMED after the cookbook NAME and the file name in the resources folder. Hence if the name of our cookbook is “sample” our custom resource is defined as “sample_website” and could be used in the cookbook as follows: sample_website 'nginx' do home '<h1>Welcome to the Sample website!</h1>' end |
|