Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Commit f8f85f3

Browse files
committed
Add short description of Policyfile syntax
1 parent 103cfb5 commit f8f85f3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

POLICYFILE_README.md

+75
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,81 @@ configuration, and requests the current policy for its name and group
106106
from the server. It then fetches the cookbooks from the new storage API,
107107
and then proceeds as normal.
108108

109+
## Policyfile Syntax
110+
111+
_Note:_ skip to the next section if you're only interested in learning
112+
the "big picture" design of this feature and the motivation for creating
113+
it.
114+
115+
A `Policyfile.rb` is the file where you name your policy, define a
116+
`run_list` for `chef-client` to use to converge your systems, and tell
117+
ChefDK where to find the cookbooks needed for your run list. It has four
118+
methods:
119+
120+
### `name "NAME"` (required)
121+
122+
This names your policy. Generally you should use a name that reflects
123+
the function that machines using this policy will perform in your
124+
infrastructure, like "jenkins-master" or "chatserver".
125+
126+
### `run_list "ITEM1", "ITEM2", ...` (required)
127+
128+
This is the `run_list` that `chef-client` will use when it applies this
129+
policy to a node (the `run_list` on the node object is ignored when
130+
using policyfiles). At this time, ChefDK does not support roles in the
131+
`run_list`, but support will be added in the future.
132+
133+
### `default_source :SOURCE_TYPE, *args`
134+
135+
This tells ChefDK where to find any cookbooks required by your
136+
`run_list` that do not have specific locations configured by the
137+
`cookbook` method (see below). If you specify a specific source for
138+
every cookbook, then you do not need to configure this.
139+
140+
### `cookbook "NAME" [, "VERSION_CONSTRAINT"] [, SOURCE_OPTIONS]
141+
142+
The `cookbook` method serves several purposes:
143+
144+
#### Add an Additional Cookbook
145+
146+
It can add a cookbook to the set of cookbooks ChefDK will compile,
147+
when that cookbook isn't needed by the `run_list`.
148+
149+
Example:
150+
151+
```ruby
152+
cookbook "apache2"
153+
```
154+
155+
#### Specify a Version Constraint
156+
157+
It can specify an additional version constraint for the cookbook. You
158+
can use this feature to constrain the versions of the cookbooks at the
159+
top level of your `run_list`.
160+
161+
Example:
162+
163+
```ruby
164+
run_list "jenkins::master"
165+
166+
# Restrict the jenkins cookbook to version 2.x, greater than 2.1
167+
cookbook "jenkins", "~> 2.1"
168+
```
169+
170+
### Specify an Alternative Source
171+
172+
ChefDK can fetch cookbooks from Supermarket, git, and local disk (other
173+
sources will be added in the future). This allows you to combine
174+
cookbooks from multiple sources into a set of cookbooks that builds your
175+
application.
176+
177+
Examples:
178+
179+
```ruby
180+
cookbook 'my_app', path: 'cookbooks/my_app'
181+
cookbook 'mysql', github: 'opscode-cookbooks/mysql', branch: 'master'
182+
```
183+
109184
## Motivation and FAQ
110185

111186
### Focus Workflow on Configuring Machines to do Useful Work

0 commit comments

Comments
 (0)