Skip to content

Commit d454ffd

Browse files
committed
More editing
Signed-off-by: Ian Maddaus <[email protected]>
1 parent 94d1dc7 commit d454ffd

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

content/recipes_yaml.md

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,6 @@ YAML recipes simplify defining Chef resources for basic use cases. While they ha
1717

1818
For most production environments, use a hybrid approach: YAML recipes for simple static configurations and Ruby recipes for complex logic. This approach balances simplicity and functionality.
1919

20-
## Use cases
21-
22-
Use YAML recipes for:
23-
24-
- Simple, static configurations
25-
- Declarative resource management
26-
- Teams preferring YAML over Ruby
27-
- Basic infrastructure as code
28-
29-
Avoid YAML recipes when you need:
30-
31-
- Dynamic node attribute access
32-
- Conditional logic
33-
- Resource notifications
34-
- Complex data transformations
35-
- Integration with Ruby libraries
36-
- Advanced Chef DSL features
37-
3820
## Create a YAML recipe
3921

4022
To create a YAML recipe, follow these steps:
@@ -75,32 +57,36 @@ To create a YAML recipe, follow these steps:
7557
In this example:
7658
7759
- the [`package` resource]({{< relref "/resources/package/" >}}) uses the `install` action and the `version` property to install Nginx 1.18.0.
78-
- the [`service` resource]({{< relref "/resources/service/" >}}) uses the `enable` and `start` actions to enable and start up Nginx.
60+
- the [`service` resource]({{< relref "/resources/service/" >}}) uses the `enable` and `start` actions to enable and start Nginx.
7961

8062
## Examples
8163

8264
### Basic file management
8365

66+
Use the [`directory` resource]({{< relref "/resources/directory">}}) to create the `/opt/app_name` directory and apply owner and group permissions to the directory. Use the [`file` resource]({{< relref "/resources/">}}) to create the `/opt/app_name/config.txt` file, add text to the file, and apply file owner and group permissions to the file.
67+
8468
```yaml
8569
---
8670
resources:
8771
- type: "directory"
88-
name: "/opt/myapp"
89-
owner: "myapp"
90-
group: "myapp"
72+
name: "/opt/app_name"
73+
owner: "app_name"
74+
group: "app_name"
9175
mode: "0755"
9276
recursive: true
9377
9478
- type: "file"
95-
name: "/opt/myapp/config.txt"
79+
name: "/opt/app_name/config.txt"
9680
content: "This is a configuration file"
97-
owner: "myapp"
98-
group: "myapp"
81+
owner: "app_name"
82+
group: "app_name"
9983
mode: "0644"
10084
```
10185

10286
### Package and service management
10387

88+
Use the [`package` resource]({{< relref "/resources/package">}}) to install Nginx and curl. Then use the [`service` resource]({{< relref "/resources/service">}}) to enable and start Nginx.
89+
10490
```yaml
10591
---
10692
resources:
@@ -119,6 +105,8 @@ resources:
119105

120106
### User management
121107

108+
Use the [`group` resource]({{< relref "/resources/group">}}) to create a group called "developers" and the [`user` resource]({{< relref "/resources/">}}) to create a user, give them properties, and assign them to the developers group.
109+
122110
```yaml
123111
---
124112
resources:
@@ -137,16 +125,39 @@ resources:
137125

138126
### Template with static variables
139127

128+
Use the [`template` resource]({{< relref "/resources/template">}}) create the `/etc/app_name/config.yml` file using the `config.yml.erb` template.
129+
140130
```yaml
141131
---
142132
resources:
143133
- type: "template"
144-
name: "/etc/myapp/config.yml"
134+
name: "/etc/app_name/config.yml"
145135
source: "config.yml.erb"
146136
owner: "root"
147137
group: "root"
148138
mode: "0644"
149-
# Note: Variables must be static, can't use node attributes
139+
```
140+
141+
### Guards
142+
143+
Some common resource functionality is also supported, as long as the value of a property can be expressed as one of the four primitive types (string, integer, boolean, array). That means it's possible to use [`only_if` or `not_if` guards]({{< relref "/resource_common#guards" >}}) as long as they shell out to Bash or PowerShell and aren't passed a Ruby block.
144+
145+
For example, this is supported:
146+
147+
```yaml
148+
resources:
149+
- type: "directory"
150+
name: "/var/www/html"
151+
only_if: "which apache2"
152+
```
153+
154+
Ruby blocks aren't supported:
155+
156+
```yaml
157+
resources:
158+
- type: "directory"
159+
name: "/var/www/html"
160+
only_if: "{ ::File.exist?('/usr/sbin/apache2') }"
150161
```
151162

152163
## Convert a YAML recipe to Ruby
@@ -217,7 +228,7 @@ resources:
217228
# Cannot do: notifies :restart, "service[nginx]", :delayed
218229
```
219230

220-
### No include/require functionality
231+
### No include or require functionality
221232

222233
YAML recipes can't include other recipes or libraries:
223234

@@ -259,7 +270,7 @@ ArgumentError: YAML recipe 'recipes/default.yml' contains multiple documents, on
259270

260271
### Ambiguous file extensions
261272

262-
Chef Infra Client returns this error if multiple recipes have the same filename but a different file extension. For example, `default.yaml` and `default.yml`.
273+
Chef Infra Client returns this error if two recipes have the same filename with different file extensions. For example, `default.yaml` and `default.yml`.
263274

264275
```text
265276
Chef::Exceptions::AmbiguousYAMLFile: Found both default.yml and default.yaml in cookbook, update the cookbook to remove one

tools/vale/Microsoft/HeadingAcronyms.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ level: warning
55
scope: heading
66
tokens:
77
- '[A-Z]{2,4}'
8+
exceptions:
9+
- API
10+
- YAML
11+
- TOML
12+
- JSON

tools/vale/Microsoft/Headings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ exceptions:
1414
- Docker
1515
- Emmet
1616
- I
17+
- JSON
1718
- Kubernetes
1819
- Linux
1920
- macOS
2021
- Marketplace
2122
- MongoDB
2223
- REPL
24+
- Ruby
2325
- Studio
2426
- TypeScript
2527
- URLs
2628
- Visual
2729
- VS
2830
- Windows
31+
- YAML

0 commit comments

Comments
 (0)