Skip to content

Commit 5a728b7

Browse files
author
jbondpdx
committed
add intro graph to resource example
1 parent 682972a commit 5a728b7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/puppet/latest/complete_resource_example.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
22
layout: default
3-
title: Complete Resource Example
3+
title: Complete resource example
44
---
55

6-
## Resource Creation
6+
You can write resource types and providers in the Puppet language. This example walks through creating resources in Puppet. Alternatively, you can use the [Puppet Resource API](./create_types_and_providers_resource_api.html) for a simpler and faster way to build types and providers.
77

8-
Nearly every resource needs to be able to be created and destroyed, and resources have to have names, so we'll start with those two features. Puppet's property support has a helper method called `ensurable` that handles modeling creation and destruction; it creates an `ensure` property and adds `absent` and `present` values for it, which in turn require three methods on the provider, `create`, `destroy`, and `exists?`. Here's the first start to the resource. We're going to create one called 'file' --- this is an example of how to create a resource for something Puppet already has.
8+
## Resource creation
9+
10+
Nearly every resource needs to be able to be created and destroyed, and resources have to have names, so we'll start with those two features. Puppet's property support has a helper method called `ensurable` that handles modeling creation and destruction; it creates an `ensure` property and adds `absent` and `present` values for it, which in turn require three methods on the provider, `create`, `destroy`, and `exists?`. Here's the first start to the resource. We're going to create one called 'file' --- this is an example of how to create a resource for something Puppet already has.
911

1012

1113
Puppet::Type.newtype(:file) do
@@ -78,11 +80,11 @@ Add this code to the provider to understand modes:
7880
File.chmod(Integer("0" + value), @resource[:name])
7981
end
8082

81-
Note that the getter method returns the value, it doesn't attempt to modify the resource itself. Also, when the setter gets passed the value it is supposed to set; it doesn't attempt to figure out the appropriate value to use. This should always be true of how providers are implemented.
83+
The getter method returns the value, but it doesn't attempt to modify the resource itself. Also, when the setter gets passed the value it is supposed to set, it doesn't attempt to figure out the appropriate value to use. This should always be true of how providers are implemented.
8284

83-
Also notice that the `ensure` property, when created by the `ensurable` method, behaves differently because it uses methods for creation and destruction of the file, whereas normal properties use getter and setter methods. When a resource is being created, Puppet expects the `create` method (or, actually, any changes done within ensure) to make any other necessary changes. This is because most often resources are created already configured correctly, so it doesn't make sense for Puppet to test it manually (for example, useradd support is set up to add all specified properties when useradd is run, so usermod doesn't need to be run afterward).
85+
Also notice that the `ensure` property, when created by the `ensurable` method, behaves differently because it uses methods for creation and destruction of the file, whereas normal properties use getter and setter methods. When a resource is being created, Puppet expects the `create` method (or, actually, any changes done within `ensure`) to make any other necessary changes. This is because most often resources are created already configured correctly, so it doesn't make sense for Puppet to test it manually (for example, `useradd` support is set up to add all specified properties when `useradd` is run, so `usermod` doesn't need to be run afterward).
8486

85-
You can see how the `absent` and `present` values are defined by looking in the property.rb file; here's the most important snippet:
87+
You can see how the `absent` and `present` values are defined by looking in the `property.rb` file; here's the most important snippet:
8688

8789
newvalue(:present) do
8890
if @resource.provider and @resource.provider.respond_to?(:create)

0 commit comments

Comments
 (0)