Skip to content

Commit b32d71a

Browse files
authored
DOC-4535 Clarify how automatic relationships work
1 parent d8d7fe6 commit b32d71a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

source/puppet/5.5/custom_types.markdown

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,26 @@ There are two parts here. The `:parent => Puppet::Parameter::Boolean` part confi
316316

317317
### Automatic relationships
318318

319-
Your type can specify automatic relationships it can have with resources. You can use autorequire, autobefore, autonotify, and autosubscribe, which all require a resource type as an argument, and your code should return a list of resource names that your resource could be related to.
320-
321-
``` ruby
322-
autorequire(:user) do
323-
self[:user]
324-
end
319+
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.
320+
321+
Sometimes there is a 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:
322+
323+
```
324+
autorequire(:file) do
325+
['/path/to/file'']
326+
end
327+
```
328+
329+
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:
330+
331+
```
332+
custom { 'a custom resource':
333+
ensure => present,
334+
require => File['/path/to/file']
335+
}
325336
```
326337

327-
Note that this won't throw an error if resources with those names do not exist; the purpose of this hook is to make sure that if any required resources are being managed, they get applied before the requiring resource.
338+
An important difference between automatic and explicit relationships is that automatic relationships do not require the other resources to exist, while explicit relationships do.
328339

329340
### Agent-side pre-run resource validation (Puppet 3.7 and later)
330341

0 commit comments

Comments
 (0)