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

Subclassing a Custom Resource


Sometimes, you need to handle more complex situations, such as supporting distinctly different operating systems, such as Linux and Windows. This can easily be handled by subclassing your Custom Resource. Let's consider a new requirement for our use case, that is, we need to extend our new appsite Custom Resource cookbook so that it will allow us to create websites on OS X and Linux using Apache, and on Windows using IIS.

In order to provide for subclassing of our Custom Resource, we will need to convert them into a library module, so let's start there.

Convert our resource into a library module

We begin by creating a new folder named "libraries" in our cookbook. Next, we create a new file in our libraries folder named website.rb and add the following contents to the file:

module AppsiteCookbook
  class Website < Chef::Resource
    resource_name :appsite_website

  end
end

This is the template used to define our library module. We are creating a new library module...