Book Image

Mastering Chef Provisioning

By : Earl Waud
Book Image

Mastering Chef Provisioning

By: Earl Waud

Overview of this book

This book will show you the best practices to describe your entire infrastructure as code. With the help of this book you can expand your knowledge of Chef because and implement robust and scalable automation solutions. You can automate and document every aspect of your network, from the hardware to software, middleware, and all your containers. You will become familiar with the Chef’s Chef Provisioning tool. You will be able to make a perfect model system where everything is represented as code beneath your fingertips. Make the best possible use of your resources, and deliver infrastructure as code, making it as versionable, testable and repeatable as application software
Table of Contents (17 chapters)
Mastering Chef Provisioning
Credits
Foreword
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Creating and using a Custom Resource


Now that we have our use case defined and a working solution created, we want to introduce updates to the cookbook to turn what we have into a better solution that uses Custom Resources. Specifically, we are going to create a "website" Custom Resource.

What makes up a Custom Resource?

Custom Resources are created by making a Ruby file in the cookbook's resources folder. The resource name will be the name of the file created. For example, if we want to create a "website" Custom Resource, we would create a new Ruby file named website.rb, as follows:

mkdir –p ~/chef-repo/cookbooks/mywebapp/resources
touch ~/chef-repo/cookbooks/mywebapp/resources/website.rb

This will create a new folder named resources and create an empty file named website.rb in that folder.

Tip

Creating a default.rb resource file: If you create a resource file named default.rb, the resource will have the same name as the cookbook.

A cookbook can have multiple resources. Each one would be defined...