Resource partials are a way of allowing resources to share common code. We recommend using partials any time you need to share code across three or more resources.
If you have three resources all which require the properties,
group to be set. Instead of writing those property definitions in each of those files, you can write the property definition in one file and include it in the three resources.
use method works similarly to the Ruby
Write the common properties and place them in a folder within the resources folder. This will stop Chef from considering them to be full resources.
# resources/_partial/_user.rb property :user, String, default: 'haproxy' property :group, String String, default: 'haproxy'
Then include them in each of the three resources with the use directive:
# resources/backend.rb use '_partial/_user'
# resources/frontend.rb use '_partial/_user'
Was this page helpful?