You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/custom_resources.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ Follow these steps to create a new custom resource:
36
36
37
37
1. Generate a new custom resource.
38
38
39
-
The `resources` directory does not exist by default in a cookbook.
39
+
The `resources` directory doesn't exist by default in a cookbook.
40
40
Generate the `resources` directory and a resource file from the `chef-repo/cookbooks` directory with the command:
41
41
42
42
```bash
@@ -140,7 +140,7 @@ where:
140
140
- `site` is the name of the custom resource. The `provides` statement makes the custom resource available for use recipes.
141
141
- `homepage` sets the default HTML for the `index.html` file with a default value of `'<h1>Hello world!</h1>'`
142
142
- the `action` block uses the built-in collection of resources to tell Chef Infra Client how to install Apache, start the service, and then create the contents of the file located at `/var/www/html/index.html`
143
-
- `action :create` is the default resource (because it is listed first); `action :delete` must be called specifically (because it is not the default action)
143
+
- `action :create` is the default resource (because it's listed first);`action :delete` must be called specifically (because it's not the default action)
144
144
145
145
Once written, you can use a custom resource in a recipe with the same syntax as Chef Infra Client built-in resources.
Copy file name to clipboardExpand all lines: content/unified_mode.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,10 @@ product = ["client"]
22
22
23
23
## Unified Mode isolation
24
24
25
-
If a Unified Mode resource calls a non-Unified Mode resource, the called resource is not executed in Unified Mode. Each resource maintains its own state whether it is in Unified Mode or not. You do not need to modify a custom resource that calls a Unified Mode resource since the calling context will not affect the resource's execution. Resources using Unified Mode may call resources not using Unified Mode and vice versa.
25
+
If a Unified Mode resource calls a non-Unified Mode resource, the called resource isn't executed in Unified Mode.
26
+
Each resource maintains its own state whether it's in Unified Mode or not.
27
+
You don't need to modify a custom resource that calls a Unified Mode resource since the calling context won't affect the resource's execution.
28
+
Resources using Unified Mode may call resources not using Unified Mode and vice versa.
26
29
27
30
## Benefits of Unified Mode
28
31
@@ -34,11 +37,12 @@ With the deferred execution of resources to converge time, the user has to under
34
37
35
38
### Elimination of lazy blocks
36
39
37
-
Several aspects of the Chef Infra Language still work but are no longer necessary in Unified Mode. Unified Mode eliminates the need for lazy blocks and the need to lazy Ruby code through a Ruby block.
40
+
Several aspects of the Chef Infra Language still work but are no longer necessary in Unified Mode.
41
+
Unified Mode eliminates the need for lazy blocks and the need to lazy Ruby code through a Ruby block.
38
42
39
43
### Rescue blocks and other Ruby constructs work correctly
40
44
41
-
In Unified Mode, it is now easy to write a rescue wrapper around a Chef Infra resource:
45
+
In Unified Mode, it's now easy to write a rescue wrapper around a Chef Infra resource:
42
46
43
47
```ruby
44
48
begin
@@ -118,7 +122,7 @@ action :install do
118
122
119
123
# the downloading of this file acts as a guard for all the later
120
124
# resources -- but if the download is successful while the later
121
-
# resources fail for some transient issue, will will not redownload on
125
+
# resources fail for some transient issue, will won't redownload on
122
126
# the next run -- we lose our edge trigger.
123
127
#
124
128
remote_file "/tmp/redis-#{version}.tar.gz"do
@@ -150,7 +154,7 @@ end
150
154
151
155
This simplified example shows how to trap exceptions from resources using normal Ruby syntax and to clean up the resource. Without Unified Mode, this syntax is impossible. Normally when the [execute]({{< relref "resources/execute" >}}) resources are parsed, they only create the objects in the `resource_collection` to later be evaluated so that no exception is thrown while Ruby is parsing the `action` block. Every action is delayed to the later converge phase. In Unified Mode, the resource runs when Ruby is done parsing its block, so exceptions happen in-line with Ruby parsing and the rescue clause now works as expected.
152
156
153
-
This is useful because the TAR extraction throws an exception (for example, the node could be out of disk space), which deletes the TAR file. The next time Chef Infra Client runs, the TAR file will be redownload. If the resource did not have file cleanup after an exception, the TAR file would remain on the client node even though the resource is not complete and the extraction did not happen, leaving the resource in a broken, indeterminate state.
157
+
This is useful because the TAR extraction throws an exception (for example, the node could be out of disk space), which deletes the TAR file. The next time Chef Infra Client runs, the TAR file will be redownload. If the resource did not have file cleanup after an exception, the TAR file would remain on the client node even though the resource isn't complete and the extraction did not happen, leaving the resource in a broken, indeterminate state.
0 commit comments