How do I share code across Chef cookbooks in a chef-repo?

前端 未结 2 895
轻奢々
轻奢々 2021-02-13 23:13

I would like to share a small handful of methods across recipes in a chef repo. I know that on a cookbook level I can put code in modules in the libraries directory (see relate

2条回答
  •  暖寄归人
    2021-02-13 23:47

    You can use a library defined function from another cookbook but you must teach Chef that your cookbook depends on the providing cookbook.

    So, for example, if in cookbook A, you have a libraries/default.rb that provides some function f, you can access it from cookbook B so long as B's metadata.rb file includes the line:

    depends "A"
    

    See the Chef documentation on metadata and libraries for more details.

提交回复
热议问题