chef-provisioning 2.7.2 → 2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +17 -0
- data/Rakefile +13 -12
- data/chef-provisioning.gemspec +2 -13
- data/lib/chef/provider/machine_batch.rb +31 -19
- data/lib/chef/provisioning/convergence_strategy/install_sh.rb +10 -2
- data/lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb +14 -6
- data/lib/chef/provisioning/machine/unix_machine.rb +1 -1
- data/lib/chef/provisioning/version.rb +3 -3
- metadata +5 -79
- data/CHANGELOG.md +0 -1015
- data/README.md +0 -332
data/README.md
DELETED
@@ -1,332 +0,0 @@
|
|
1
|
-
Chef Provisioning
|
2
|
-
==========
|
3
|
-
[![Status](https://travis-ci.org/chef/chef-provisioning.svg?branch=master)](https://travis-ci.org/chef/chef-provisioning)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/chef-provisioning.svg)](http://badge.fury.io/rb/chef-provisioning)
|
5
|
-
|
6
|
-
Please join us in Slack by signing up at http://community-slack.chef.io/ and joining `#chef-provisioning`
|
7
|
-
|
8
|
-
Overview
|
9
|
-
==========
|
10
|
-
|
11
|
-
Chef Provisioning is a Cookbook and Recipe based approach for managing your infrastructure. Users can codify their infrastructure and use Chef to converge their infrastructure to the desired state. It has a plugin model (called Drivers) to manage different infrastructures, including AWS, Azure and Fog.
|
12
|
-
|
13
|
-
Chef Provisioning is maintained according to the [Chef Maintenance Policy](https://github.com/chef/chef-rfc/blob/master/rfc030-maintenance-policy.md).
|
14
|
-
|
15
|
-
Drivers
|
16
|
-
-------------
|
17
|
-
|
18
|
-
Due to the age and engagement level with different Drivers they have fallen into two categories - maintained and unmaintained.
|
19
|
-
|
20
|
-
Maintained drivers have a representative in the maintenance policy and get triaged / discussed during office hours. They are
|
21
|
-
|
22
|
-
| [AWS](https://github.com/chef/chef-provisioning-aws) | [Fog](https://github.com/chef/chef-provisioning-fog) |
|
23
|
-
| ---- | ---- |
|
24
|
-
| [![Gem Version](https://badge.fury.io/rb/chef-provisioning-aws.svg)](http://badge.fury.io/rb/chef-provisioning-aws) | [![Gem Version](https://badge.fury.io/rb/chef-provisioning-fog.svg)](http://badge.fury.io/rb/chef-provisioning-fog) |
|
25
|
-
|
26
|
-
Maintained by Chef-Partners:
|
27
|
-
|
28
|
-
* [vSphere](https://github.com/chef-partners/chef-provisioning-vsphere)
|
29
|
-
* [vra](https://github.com/chef-partners/chef-provisioning-vra)
|
30
|
-
|
31
|
-
Maintained, not by Chef:
|
32
|
-
|
33
|
-
* [AzureRM](https://github.com/pendrica/chef-provisioning-azurerm)
|
34
|
-
|
35
|
-
Unmaintained Drivers are at risk of becoming stale. They are:
|
36
|
-
|
37
|
-
* [Docker](https://github.com/chef/chef-provisioning-docker)
|
38
|
-
* [ssh](https://github.com/chef/chef-provisioning-ssh)
|
39
|
-
* [Vagrant](https://github.com/chef/chef-provisioning-vagrant)
|
40
|
-
* [LXC](https://github.com/chef/chef-provisioning-lxc)
|
41
|
-
* [Hanlon](https://github.com/chef/chef-provisioning-hanlon)
|
42
|
-
|
43
|
-
Target Audience
|
44
|
-
-------------
|
45
|
-
|
46
|
-
Chef Provisioning is a good fit for people who use or want to use the Chef ecosystem to manage their infrastructure. Infrastructure is represented as Chef Resources and managed in Chef Recipes and Cookbooks. These recipes run on a provisioner node and attempt to converge the infrastructure idempotently. The AWS driver is the most used, the most tested and receives the most updates.
|
47
|
-
|
48
|
-
Chef Provisioning and its Drivers are maintained by the open source community. They currently have a slow tempo for issue triage and pull request merging. Troubleshooting a bug may require stepping through the Ruby Chef codebase and engaging the community.
|
49
|
-
|
50
|
-
If you are new to Chef and Chef Provisioning, learning both can be daunting. If you are not familiar with Ruby as well, double the learning curve. Successful provisioning users know how they want to manage their cookbooks. Generally this is some CI/CD pipeline.
|
51
|
-
|
52
|
-
Chef is very flexible which allows customized provisioning solutions at the cost of high complexity. This makes it hard to document all the possible use cases. Patterns (for example, how to manage the provisioning node and run the provisioning recipes) are not well documented.
|
53
|
-
|
54
|
-
Chef Provisioning should be used to manage infrastructure (CRUD operations) and register Chef nodes with the server for the first time only. Other use cases (like scheduling chef runs, node inventory or reporting) are not supported.
|
55
|
-
|
56
|
-
Documentation
|
57
|
-
-------------
|
58
|
-
|
59
|
-
These are the primary documents to help learn about using Provisioning and creating Provisioning drivers:
|
60
|
-
|
61
|
-
* [Chef Docs](https://docs.chef.io/provisioning.html)
|
62
|
-
* [Frequently Asked Questions](https://github.com/chef/chef-provisioning/blob/master/docs/faq.md)
|
63
|
-
* [Configuration](https://github.com/chef/chef-provisioning/blob/master/docs/configuration.md#configuring-and-using-provisioning-drivers)
|
64
|
-
* [Writing Drivers](https://github.com/chef/chef-provisioning/blob/master/docs/building_drivers.md#writing-drivers)
|
65
|
-
* [Embedding](https://github.com/chef/chef-provisioning/blob/master/docs/embedding.md)
|
66
|
-
|
67
|
-
Media
|
68
|
-
-----
|
69
|
-
[This video](https://www.youtube.com/watch?v=Yb8QdL30WgM) explains the basics of chef-provisioning (though provisioners are now called drivers). Slides (more up to date) are [here](http://slides.com/jkeiser/chef-metal).
|
70
|
-
|
71
|
-
Date | Blog
|
72
|
-
-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
73
|
-
2014-12-15 | [Using Chef Provisioning to Build Chef Server](https://www.chef.io/blog/2014/12/15/sysadvent-day-14-using-chef-provisioning-to-build-chef-server/)
|
74
|
-
2014-11-12 | [Chef Launches Policy-Based Provisioning](https://www.chef.io/blog/2014/11/12/chef-launches-policy-based-provisioning/)
|
75
|
-
2014-11-12 | [Chef Provisioning: Infrastructure As Code](https://www.chef.io/blog/2014/11/12/chef-provisioning-infrastructure-as-code/)
|
76
|
-
2014-06-03 | [machine_batch and parallelization](https://github.com/chef/chef-provisioning/blob/master/docs/blogs/2012-05-28-machine_batch.html.markdown#chef-provisioning-parallelization)
|
77
|
-
2014-06-03 | [Chef Provisioning, Configuration and Drivers](https://github.com/chef/chef-provisioning/blob/master/docs/blogs/2012-05-22-new-driver-interface.html.markdown#chef-provisioning-configuration-and-drivers)
|
78
|
-
2014-03-04 | [Chef Metal 0.2: Overview](http://www.chef.io/blog/2014/03/04/chef-metal-0-2-release/) - this is a pretty good overview (though dated).
|
79
|
-
2013-12-20 | [Chef Metal Alpha](http://www.chef.io/blog/2013/12/20/chef-metal-alpha/)
|
80
|
-
|
81
|
-
Try It Out
|
82
|
-
----------
|
83
|
-
|
84
|
-
You can try out Chef Provisioning in many different flavors.
|
85
|
-
|
86
|
-
### Vagrant
|
87
|
-
|
88
|
-
To give it a spin, install the latest ChefDK, Vagrant and VirtualBox. Run the following from the `chef-provisioning/docs/examples` directory:
|
89
|
-
|
90
|
-
```
|
91
|
-
export CHEF_DRIVER=vagrant
|
92
|
-
export VAGRANT_DEFAULT_PROVIDER=virtualbox
|
93
|
-
chef-client -z vagrant_linux.rb simple.rb
|
94
|
-
```
|
95
|
-
|
96
|
-
This will create two vagrant precise64 linux boxes, "mario" and "luigi1", in `~/machinetest`, bootstrapped to an empty runlist. For Windows, you can replace `myapp::linux` with `myapp::windows`, but you'll need your own Windows vagrant box to do that (licensing!).
|
97
|
-
|
98
|
-
### AWS
|
99
|
-
|
100
|
-
If you have an AWS account, you can spin up a machine there like this:
|
101
|
-
|
102
|
-
```
|
103
|
-
export CHEF_DRIVER=aws
|
104
|
-
chef-client -z simple.rb
|
105
|
-
```
|
106
|
-
|
107
|
-
This will create two linux boxes in the AWS account referenced by your default profile in `~/.aws/config` (or your environment variables).
|
108
|
-
|
109
|
-
### DigitalOcean
|
110
|
-
|
111
|
-
If you are on DigitalOcean and using the `tugboat` gem, you can do this:
|
112
|
-
|
113
|
-
```
|
114
|
-
export CHEF_DRIVER=fog:DigitalOcean
|
115
|
-
chef-client -z simple.rb
|
116
|
-
```
|
117
|
-
|
118
|
-
If you aren't using the `tugboat` gem, you can put `driver` and `driver_options` into your `.chef/knife.rb` file.
|
119
|
-
|
120
|
-
This will use your tugboat settings to create whatever sort of instance you normally create.
|
121
|
-
|
122
|
-
### Cleaning up
|
123
|
-
|
124
|
-
When you are done with the examples, run this to clean up:
|
125
|
-
|
126
|
-
```
|
127
|
-
chef-client -z destroy_all.rb
|
128
|
-
```
|
129
|
-
|
130
|
-
What Is Chef Provisioning?
|
131
|
-
-------------------
|
132
|
-
|
133
|
-
Chef Provisioning has two major abstractions: the machine resource, and drivers.
|
134
|
-
|
135
|
-
### The `machine` resource
|
136
|
-
|
137
|
-
You declare what your machines do (recipes, tags, etc.) with the `machine` resource, the fundamental unit of Chef Provisioning. You will typically declare `machine` resources in a separate, OS/provisioning-independent file that declares the *topology* of your app--your machines and the recipes that will run on them.
|
138
|
-
|
139
|
-
The machine resources from the [cluster.rb example](https://github.com/chef/chef-provisioning/blob/master/docs/examples/cluster.rb) are pretty straightforward. Here's a copy/paste:
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
# Database!
|
143
|
-
machine 'mario' do
|
144
|
-
recipe 'postgresql'
|
145
|
-
recipe 'mydb'
|
146
|
-
tag 'mydb_master'
|
147
|
-
end
|
148
|
-
|
149
|
-
num_webservers = 1
|
150
|
-
|
151
|
-
# Web servers!
|
152
|
-
1.upto(num_webservers) do |i|
|
153
|
-
machine "luigi#{i}" do
|
154
|
-
recipe 'apache'
|
155
|
-
recipe 'mywebapp'
|
156
|
-
end
|
157
|
-
end
|
158
|
-
```
|
159
|
-
|
160
|
-
You will notice the dynamic nature of the number of web servers. It's all code, your imagination is the limit :)
|
161
|
-
|
162
|
-
### Drivers
|
163
|
-
|
164
|
-
Drivers handle the real work of getting those abstract definitions into real, physical form. They handle the following tasks, idempotently (you can run the resource again and again and it will only create the machine once--though it may notice things are wrong and fix them!):
|
165
|
-
|
166
|
-
* Acquiring machines from the cloud, creating containers or VMs, or grabbing bare metal
|
167
|
-
* Connecting to those machines via ssh, winrm, or other transports
|
168
|
-
* Bootstrapping chef onto the machines and converging the recipes you suggested
|
169
|
-
|
170
|
-
The driver API is separated out so that new drivers can be made with minimal effort (without having to rewrite ssh, tunneling, bootstrapping, and OS support). But to the user, they appear as a single thing, so that the machine acquisition can use its smarts to autodetect the other bits (transports, OS's, etc.).
|
171
|
-
|
172
|
-
Drivers save their data in the Chef node itself, so that they will be accessible to everyone who is using the Chef server to manage the nodes.
|
173
|
-
|
174
|
-
### Machine options
|
175
|
-
|
176
|
-
You can pass machine options that will be used by `machine`, `machine_batch` and `machine_image` to
|
177
|
-
configure the machine:
|
178
|
-
|
179
|
-
```ruby
|
180
|
-
with_machine_options({
|
181
|
-
convergence_options: {
|
182
|
-
chef_version: "12.4.1",
|
183
|
-
prerelease: false,
|
184
|
-
chef_client_timeout: 120*60, # Default: 2 hours
|
185
|
-
chef_config: "log_level :debug\\n", # String containing additional text to inject into client.rb
|
186
|
-
chef_server: "http://my.chef.server/", # TODO could conflict with https://github.com/chef/chef-provisioning#pointing-boxes-at-chef-servers
|
187
|
-
bootstrap_proxy: "http://localhost:1234",
|
188
|
-
bootstrap_no_proxy: "localhost, *.example.com, my.chef.server",
|
189
|
-
rubygems_url: "http://mirror.example.org",
|
190
|
-
ssl_verify_mode: :verify_peer,
|
191
|
-
client_rb_path: "/etc/chef/client.rb", # <- DEFAULT, overwrite if necessary
|
192
|
-
client_pem_path: "/etc/chef/client.pem", # <- DEFAULT, overwrite if necessary
|
193
|
-
allow_overwrite_keys: false, # If there is an existing client.pem this needs to be true to overwrite it
|
194
|
-
private_key_options: {}, # TODO ????? Something to do with creating node object
|
195
|
-
source_key: "", # ?????
|
196
|
-
source_key_pass_phrase: "", # ?????
|
197
|
-
source_key_path: "", # ?????
|
198
|
-
public_key_path: "", # ?????
|
199
|
-
public_key_format: "", # ?????
|
200
|
-
admin: "", # ?????
|
201
|
-
validator: "", # ?????
|
202
|
-
ohai_hints: { :ec2 => { :key => :value } }, # Map from hint file name to file contents, this would create /etc/chef/ohai/hints/ec2.json,
|
203
|
-
ignore_failure: [1, 5..10, SomeSpecificError], # If true don't let a convergence failure on provisioned machine stop the provisioning workstation converge. Can also provide a single exit code to ignore (no array) or `true` to ignore all RuntimeErrors
|
204
|
-
# The following are only available for Linux machines
|
205
|
-
install_sh_url: "https://www.chef.io/chef/install.sh", # <- DEFAULT, overwrite if necessary
|
206
|
-
install_sh_path: "/tmp/chef-install.sh", # <- DEFAULT, overwrite if necessary
|
207
|
-
install_sh_arguments: "-P chefdk", # Additional commands to pass to install.sh
|
208
|
-
# The following are only available for Windows machines
|
209
|
-
install_msi_url: "foo://bar.com"
|
210
|
-
},
|
211
|
-
ssh_username: "ubuntu", # Username to use for ssh and WinRM
|
212
|
-
ssh_gateway: "user@gateway", # SSH gateway configuration
|
213
|
-
ssh_options: { # a list of options to Net::SSH.start
|
214
|
-
:auth_methods => [ 'publickey' ], # DEFAULT
|
215
|
-
:keys_only => true, # DEFAULT
|
216
|
-
:host_key_alias => "#{instance.id}.AWS", # DEFAULT
|
217
|
-
:key_data => nil, # use key from ssh-agent instead of a local file; remember to ssh-add your keys!
|
218
|
-
:forward_agent => true, # you may want your ssh-agent to be available on your provisioned machines
|
219
|
-
:never_forward_localhost => false, # This will, if set, disable SSH forwarding if it does not work/make sense in your envirnoment
|
220
|
-
:remote_forwards => [
|
221
|
-
# Give remote host access to squid proxy on provisioning node
|
222
|
-
{:remote_port => 3128, :local_host => 'localhost', :local_port => 3128,},
|
223
|
-
# Give remote host access to private git server
|
224
|
-
{:remote_port => 2222, :local_host => 'git.example.com', :local_port => 22,},
|
225
|
-
],
|
226
|
-
# You can send net-ssh log info to the Chef::Log if you are having
|
227
|
-
# trouble with ssh.
|
228
|
-
:logger => Chef::Log,
|
229
|
-
# If you use :logger => Chef::Log and :verbose then your :verbose setting
|
230
|
-
# will override the global Chef::Config. Probably don't want to do this:
|
231
|
-
#:verbose => :warn,
|
232
|
-
}
|
233
|
-
})
|
234
|
-
```
|
235
|
-
|
236
|
-
This options hash can be supplied to either `with_machine_options` or directly into the `machine_options`
|
237
|
-
attribute.
|
238
|
-
|
239
|
-
Individual drivers will often add their own driver specific config. For example, AWS expects a `:bootstrap_options` hash at the same level as `:convergence_options`.
|
240
|
-
|
241
|
-
### Anatomy of a Recipe
|
242
|
-
|
243
|
-
The ChefDK comes with a provisioner for Vagrant, an abstraction that covers VirtualBox, VMware and other Virtual Machine drivers. In docs/examples, you can run this to try it:
|
244
|
-
|
245
|
-
```ruby
|
246
|
-
export CHEF_DRIVER=vagrant
|
247
|
-
export VAGRANT_DEFAULT_PROVIDER=virtualbox
|
248
|
-
chef-client -z vagrant_linux.rb simple.rb
|
249
|
-
```
|
250
|
-
|
251
|
-
To use with VMware, simply update the prior example to read ```export VAGRANT_DEFAULT_PROVIDER=vmware_fusion```
|
252
|
-
|
253
|
-
This is a chef-client run, which runs multiple **recipes.** Chef Provisioning is nothing but resources you put in recipes.
|
254
|
-
|
255
|
-
The driver is specified on the command line. Drivers are URLs. You could use `vagrant:~/vms` or `fog:AWS:default:us-east-1' as driver URLs. More information [here.](https://github.com/chef/chef-provisioning/blob/master/docs/configuration.md#setting-the-driver-with-a-driver-url)
|
256
|
-
|
257
|
-
The `vagrant_linux.rb` recipe handles the physical specification of the machines and Vagrant box:
|
258
|
-
|
259
|
-
```ruby
|
260
|
-
require 'chef/provisioning/vagrant_driver'
|
261
|
-
|
262
|
-
vagrant_box 'precise64' do
|
263
|
-
url 'http://files.vagrantup.com/precise64.box'
|
264
|
-
end
|
265
|
-
|
266
|
-
with_machine_options :vagrant_options => {
|
267
|
-
'vm.box' => 'precise64'
|
268
|
-
}
|
269
|
-
```
|
270
|
-
|
271
|
-
`require 'chef/provisioning/vagrant_driver'` is how we bring in the `vagrant_box` resource.
|
272
|
-
|
273
|
-
`vagrant_box` makes sure a particular vagrant box exists, and lets you specify `machine_options` for things like port forwarding, OS definitions, and any other vagrant-isms.
|
274
|
-
|
275
|
-
Typically, you declare these in separate files from your machine resources. Chef Provisioning picks up the drivers and machine_options you have declared, and uses them to instantiate the machines you request. The actual machine definitions, in this case, are in `simple.rb`, and are generic--you could use them against Azure or EC2 as well:
|
276
|
-
|
277
|
-
```ruby
|
278
|
-
machine 'mario' do
|
279
|
-
tag 'itsame'
|
280
|
-
end
|
281
|
-
```
|
282
|
-
|
283
|
-
Other directives, like `recipe 'apache'`, help you set run lists and other information about the machine.
|
284
|
-
|
285
|
-
### Pointing Boxes at Chef Servers
|
286
|
-
|
287
|
-
By default, Chef Provisioning will put your boxes on the same Chef server you started chef-client with (in the case of -z, that's a local chef-zero server). Sometimes you want to put your boxes on different servers. There are a couple of ways to do that:
|
288
|
-
|
289
|
-
```ruby
|
290
|
-
with_chef_local_server :chef_repo_path => '~/repo'
|
291
|
-
```
|
292
|
-
|
293
|
-
`with_chef_local_server` is a generic directive that creates a chef-zero server pointed at the given repository. nodes, clients, data bags, and all data will be stored here on your provisioner machine if you do this.
|
294
|
-
|
295
|
-
You can use `with_chef_server` instead if you want to point at OSS, Hosted or Enterprise Chef, and if you don't specify a Chef server at all, it will use the one you are running chef-client against. Keep in mind when using `with_chef_server` and running `chef-client -z` on your workstation that you will also need to set the client name and signing key for the chef server. If you've already got knife.rb set up, then something like this in the provisioning recipe will correctly create a client for the chef server on instance using your knife.rb configuration:
|
296
|
-
|
297
|
-
```ruby
|
298
|
-
with_chef_server "https://chef-server.example.org",
|
299
|
-
:options =>{
|
300
|
-
:client_name => Chef::Config[:node_name],
|
301
|
-
:signing_key_filename => Chef::Config[:client_key]
|
302
|
-
}
|
303
|
-
```
|
304
|
-
|
305
|
-
Finally, you can specify a Chef Server for an individual machine by using the `chef_server` attribute. This attribute takes the same additional options (`:client_name`, `:signing_key_filename`) that `with_chef_server` does.
|
306
|
-
|
307
|
-
```ruby
|
308
|
-
machine 'mario' do
|
309
|
-
chef_server :chef_server_url => "https://chef-server.example.org"
|
310
|
-
end
|
311
|
-
```
|
312
|
-
|
313
|
-
### Configuring ACLs
|
314
|
-
|
315
|
-
If you want to run your provisionning recipes from an actual chef node, rather than from your workstation, you need to give that node's client enough rights to create the node and client he'll be provisioning on the chef server. Without those additional rights, the provisioning will fail with a error along the lines of `chef_client[mymachine] had an error: Net::HTTPServerException: 403 "Forbidden"`.
|
316
|
-
|
317
|
-
A clean solution to this problem is to use [knife-acl](https://github.com/chef/knife-acl) to define a `provisioners` group with the required rights, and add your client to it:
|
318
|
-
|
319
|
-
```shellsession
|
320
|
-
$> chef gem install knife-acl
|
321
|
-
$> knife group create provisioners
|
322
|
-
$> knife acl add group provisioners containers clients read,create,update,delete,grant
|
323
|
-
$> knife acl add group provisioners containers nodes read,create,update,delete,grant
|
324
|
-
$> knife group add client my_provisioning_client_name provisioners
|
325
|
-
```
|
326
|
-
|
327
|
-
Bugs and The Plan
|
328
|
-
-----------------
|
329
|
-
|
330
|
-
Please submit bugs, gripes and feature requests at [https://github.com/chef/chef-provisioning/issues](https://github.com/chef/chef-provisioning/issues) and join us in the Slack room to chat.
|
331
|
-
|
332
|
-
To contribute, just make a PR in the appropriate repo following the Chef [contribution process](https://github.com/chef/chef/blob/master/CONTRIBUTING.md#contribution-process).
|