Automatic relationships

Use automatic relationships to define the ordering of resources.

By default, Puppet includes and processes resources in the order they are defined in their manifest. However, there are times when resources need to be applied in a different order. The Puppet language provides ways to express explicit ordering such as relationship metaparameters (require, before, etc), chaining arrows and the require and contain functions.

Sometimes there is natural relationship between your custom type and other resource types. For example, ssh authorized keys can only be managed after you create the home directory and you can only manage files after you create their parent directories. You can add explicit relationships for these, but doing so can be restrictive for others who may want to use your custom type. Automatic relationships provide a way to define implicit ordering. For example, to automatically add a require relationship from your custom type to a configuration file that it depends on, add the following to your custom type:

autorequire(:file) do
  ['/path/to/file']
end

The Ruby symbol :file refers to the type of resource you want to require, and the array contains resource title(s) with which to create the require relationship(s). The effect is nearly equivalent to using an explicit require relationship:

custom { <CUSTOM RESOURCE>:
  ensure => present,
  require => File['/path/to/file']
}

An important difference between automatic and explicit relationships is that automatic relationships do not require the other resources to exist, while explicit relationships do.