Chef libraries or definitions?

前端 未结 2 452
抹茶落季
抹茶落季 2020-12-07 16:49

Being relatively new to Chef, I am required to create libraries or definitions from existing recipes.

There recipes use bash resource, ruby block resource (which not

2条回答
  •  爱一瞬间的悲伤
    2020-12-07 17:50

    Modern Chef terminology has rebranded "LWRPs" as "Custom Resources" and the "Provider" that is the "P" of the "LWRP" has melted into the background and users just run actions now (the action_class is the way to access the old provider class).

    Definitions still exist, are still discouraged, and still have known bugs which will never be fixed. There is no reason to use them.

    Custom Resources are what everyone should use. More people should move recipe code into custom resources for reusability. The basic steps are simple:

    1. Move the code into a resources file
    2. Wrap the code with an action
    3. Add a provides line for the name of the resource
    4. Change the include_recipe call in recipes into a call to the custom resource.

    That's all that is necessary for simple cases. Once that is done the resource can now be extended by adding properties, or existing node attributes can be converted into properties (the node attributes can be pushed back into the call to the resource from recipe mode).

    For modern resources on Chef-15/16 consider setting unified_mode true to remove the compile/converge phase from the custom resource and simplify writing the resource.

    For an example of the conversion of a simple recipe to a custom resource see this answer

提交回复
热议问题