BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Chef Infra 16 Released with Resource Partials and YAML Support

Chef Infra 16 Released with Resource Partials and YAML Support

This item in japanese

Bookmarks

Chef has announced the release of Chef Infra 16 with a number of new features to improve creating, customizing, and updating Chef policies. This release includes YAML support for recipes, new functionality to reduce code duplication, and improvements to how Chef Infra handles mixed custom resources.

In version 16, it is now possible to define reusable portions of code known as resource partials. These are stored within a cookbook's /resources directory similar to existing custom resources, however these begin with the _ prefix. They are called using a newly introduced use helper within a resource. For example this could be used to define helper methods for use within actions:

resources/_api_auth_helpers.rb:

def make_api_call(endpoint, value)
  # API call code here
end
resources/mything.rb:

property :another_property, String
property :yet_another_property, String

action :create do
  # some create logic
end

action_class do
  use 'api_auth_helpers'
End

Included with this addition is custom resource unified mode. Unified mode allows for a single phase of execution for Chef resources and Ruby code. Previously it was possible to have mix-ins of Chef Infra resources and Ruby code, however the Ruby was evaluated first then the resources would be converged. By opting into unified mode there is a single phase per resource where all Ruby and Chef Infra resources are executed at once. Opting in is done by adding the property unified_mode true to the resource:

property :Some_property, String

unified_mode true

action :create do
  # some code
End

This release also adds YAML support for writing recipes. To write in YAML, Chef resources and user-defined parameters can be added as elements in the resources hash:

---
resources:
  - type: "package"
    name: "httpd"
  - type: "template"
    name: "/var/www/html/index.html"
    source: "index.html.erb"
  - type: "service"
    name: "httpd"
    action:
      - enable
      - start

It should be noted that this implementation is minimal and meant for simple use cases. If needed YAML recipes can be converted to DSL via the command knife yaml convert.

This release also brings performance improvements to speed up client runs on Windows. This is coupled with the client being up to 30% smaller on disk as the Chef team has removed a number of unnecessary files. The client now also supports multiple Linux flavours on ARM including Ubuntu 20.04, Amazon Linux 2, RHEL 8, and SLES 15.

With the release of Chef Infra 16, version 14 is officially moved into end of life. Version 15 will continue to be supported with patches as part of Chef's commitment to maintaining support for the latest two major releases. More details on the changes introduced in this release can be found in the official release notes.

Rate this Article

Adoption
Style

BT