Search code examples
rubychef-infracookbook

How to implement constants across custom resources in Chef?


I am writing a cookbook that defines four custom resources. There are multiple constants that should be shared across all of the resources (permissions for certain types of files, prefixes for names, relative paths etc...).

How can I share these constants across multiple custom resources?


Solution

  • Put em' in a module under libraries/default.rb:

    module MyCookbook
      BASE_PATH = '/foo'
    end
    
    # And then in the resource
    property(:path, default: MyCookbook::BASE_PATH)
    

    or somesuch.