Using autorequire for implicit relationships

To make it easier for users of your type, you can use autorequire  to avoid tediously specifying a lot of explicit relationships in longhand between resources. The autorequire method establishes implicit ordering between resources in the catalog. A typical example of this would be filing resources depending on their parent directories.

For example, in our type, if the source parameter is a file path, then we should ensure the corresponding file resource is managed first, as shown in the following code:

Puppet::Type.newtype(:mynewtype) do   ...   autorequire(:file) do     self[:source]   end   ... end

Manually specified dependencies in the Puppet DSL have a higher precedence for the compiler than the implicit ...

Get Mastering Puppet 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.