README.md in clc-fork-chef-metal-0.11.beta.6 vs README.md in clc-fork-chef-metal-0.11.2.alpha.1

- old
+ new

@@ -1,35 +1,76 @@ Chef Metal ========== This library solves the problem of repeatably creating machines and infrastructures in Chef. It has a plugin model that lets you write bootstrappers for your favorite infrastructures, including VirtualBox, EC2, LXC, bare metal, and many more! -Currently, chef-metal supports vagrant, Unixes/ssh, and Windows/winrm with real chef-servers or with automagical chef-zero tunneling. Fog and Docker support (to cover EC2 and LXC) are next up. Further out, we'd like to extend support to image factories (using the machine resource to produce images) and PXE support. +[This video](https://www.youtube.com/watch?v=Yb8QdL30WgM) explains the basics of chef-metal (though provisioners are now called drivers). Slides (more up to date) are [here](http://slides.com/jkeiser/chef-metal). +Date | Blog +-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------- +6/3/2014 | [machine_batch and parallelization](https://github.com/opscode/chef-metal/blob/master/docs/blogs/2012-05-28-machine_batch.html.markdown#chef-metal-parallelization) +6/3/2014 | [Chef Metal, Configuration and Drivers](https://github.com/opscode/chef-metal/blob/master/docs/blogs/2012-05-22-new-driver-interface.html.markdown#chef-metal-configuration-and-drivers) +3/4/2014 | [Chef Metal 0.2: Overview](http://www.getchef.com/blog/2014/03/04/chef-metal-0-2-release/) - this is a pretty good overview (though dated). +12/20/2014 | [Chef Metal Alpha](http://www.getchef.com/blog/2013/12/20/chef-metal-alpha/) + Try It Out ---------- -To give it a spin, get chef 11.8 or greater try this: +You can try out Metal in many different flavors. - git clone https://github.com/opscode/cheffish.git - cd cheffish - rake install - cd .. +HINT: chef-metal looks prettiest with chef 11.14 alpha. `gem install chef --pre` to get it. - git clone https://github.com/opscode/chef-metal.git - cd chef-metal - rake install - - cd chef-metal - chef-client -z -o myapp::vagrant,myapp::linux,myapp::small +### Vagrant +To give it a spin, install Vagrant and VirtualBox and try this from the `chef-metal/docs/examples` directory: + +``` +gem install chef-metal +export CHEF_DRIVER=vagrant +chef-client -z vagrant_linux.rb simple.rb +``` + 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!). +### AWS + +If you have an AWS account, you can spin up a machine there like this: + +``` +gem install chef-metal +export CHEF_DRIVER=fog:AWS +chef-client -z simple.rb +``` + +This will create two linux boxes in the AWS account referenced by your default profile in `~/.aws/config` (or your environment variables). + +### DigitalOcean + +If you are on DigitalOcean and using the `tugboat` gem, you can do this: + +``` +gem install chef-metal +export CHEF_DRIVER=fog:DigitalOcean +chef-client -z simple.rb +``` + +If you aren't using the `tugboat` gem, you can put `driver` and `driver_options` into your `.chef/knife.rb` file. + +This will use your tugboat settings to create whatever sort of instance you normally create. + +### Cleaning up + +When you are done with the examples, run this to clean up: + +``` +chef-client -z destroy_all.rb +``` + What Is Chef Metal? ------------------- -Chef Metal has two major abstractions: the machine resource, and provisioners. +Chef Metal has two major abstractions: the machine resource, anf drivers. ### The `machine` resource You declare what your machines do (recipes, tags, etc.) with the `machine` resource, the fundamental unit of Chef Metal. 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. @@ -52,150 +93,145 @@ end ``` You will notice the dynamic nature of the number of web servers. It's all code, your imagination is the limit :) -Kitchen -------- +### Drivers -Chef Metal also works with Test Kitchen, allowing you to test entire clusters, not just machines! The repository for the kitchen-metal gem is https://github.com/doubt72/kitchen-metal. +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!): -Provisioners ------------- - -Provisioners 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!): - * Acquiring machines from the cloud, creating containers or VMs, or grabbing bare metal * Connecting to those machines via ssh, winrm, or other transports * Bootstrapping chef onto the machines and converging the recipes you suggested -The provisioner API is separated out so that new provisioners 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.). +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.). -Provisioners 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. +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. -Provisioners each have their own repository. Current provisioners: +Drivers each have their own repository. Current drivers: **Cloud:** - [FOG: EC2, DigitalOcean, OpenStack, etc.](https://github.com/opscode/chef-metal-fog) **Virtualization:** - [Vagrant: VirtualBox, VMWare Fusion, etc.](https://github.com/opscode/chef-metal-vagrant) +- [VSphere](https://github.com/RallySoftware-cookbooks/chef-metal-vsphere) (not yet up to date with 0.11) **Containers:** -- [LXC](https://github.com/opscode/chef-metal-lxc) -- [Docker](https://github.com/opscode/chef-metal-docker) +- [LXC](https://github.com/opscode/chef-metal-lxc) (not yet up to date with 0.11) +- [Docker](https://github.com/opscode/chef-metal-docker) (not yet up to date with 0.11) **Bare Metal:** -- [SSH (no PXE)](https://github.com/double-z/chef-metal-ssh) +- [SSH (no PXE)](https://github.com/double-z/chef-metal-ssh) (not yet up to date with 0.11) -### Vagrant +### Anatomy of a Recipe -chef-zero comes with a provisioner for Vagrant, an abstraction that covers VirtualBox, VMWare and other Virtual Machine drivers. To run it, you can check out the sample recipes with: +chef-zero 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: +```ruby +export CHEF_DRIVER=vagrant +chef-client -z vagrant_linux.rb simple.rb ``` -chef-client -z -o myapp::vagrant,myapp::linux,myapp::small -``` -The provisioner specification is in myapp::vagrant and myapp::linux [sample recipes](https://github.com/opscode/chef-metal/tree/master/cookbooks/myapp/recipes), copy/pasted here for your convenience: +This is a chef-client run, which runs multiple **recipes.** Chef Metal is nothing but resources you put in recipes. -```ruby -vagrant_cluster "#{ENV['HOME']}/machinetest" +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/opscode/chef-metal/blob/master/docs/configuration.md#setting-the-driver-with-a-driver-url) -directory "#{ENV['HOME']}/machinetest/repo" -with_chef_local_server :chef_repo_path => "#{ENV['HOME']}/machinetest/repo" +The `vagrant_linux.rb` recipe handles the physical specification of the machines and Vagrant box: +```ruby +require 'chef_metal_vagrant' + vagrant_box 'precise64' do - url 'http://files.vagrantup.com/precise32.box' + url 'http://files.vagrantup.com/precise64.box' end + +with_machine_options :vagrant_options => { + 'vm.box' => 'precise64' +} ``` -`vagrant_cluster` declares a directory where all the vagrant definitions will be stored, and uses `with_provisioner` internally to tell Chef Metal that this is the provisioner we want to use for machines. +`require 'chef_metal_vagrant'` is how we bring in the `vagrant_box` resource. -`vagrant_box` makes sure a particular vagrant box exists, and lets you specify `provisioner_options` for things like port forwarding, OS definitions, and any other vagrant-isms. A more complicated vagrant box, with provisioner options, can be found in [myapp::windows](https://github.com/opscode/chef-metal/blob/master/cookbooks/myapp/recipes/windows.rb). +`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. -`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. 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 will correctly create a client for the chef server on instance using your knife.rb configuration: +Typically, you declare these in separate files from your machine resources. Chef Metal 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: ```ruby -require 'chef/config' - -with_chef_server "https://chef-server.example.org", { - :client_name => Chef::Config[:node_name], - :signing_key_filename => Chef::Config[:client_key] -} -``` - -Typically, you declare these in separate files from your machine resources. Chef Metal picks up the provisioners you have declared, and uses them to instantiate the machines you request. The actual machine definitions, in this case, are in `myapp::small`, and are generic--you could use them against EC2 as well: - -```ruby machine 'mario' do - recipe 'postgresql' - recipe 'mydb' - tag 'mydb_master' + tag 'itsame' end - -num_webservers = 1 - -1.upto(num_webservers) do |i| - machine "luigi#{i}" do - recipe 'apache' - recipe 'mywebapp' - end -end ``` -### Fog (EC2 and friends) +Other directives, like `recipe 'apache'`, help you set run lists and other information about the machine. -chef-metal also comes with a [Fog](http://fog.io/) provisioner that handles provisioning to Amazon's EC2 and other cloud drivers. (Only EC2 has been tested so far.) Before you begin, you will need to put your AWS credentials in ~/.aws/config in the format [mentioned in Option 1 here](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#d0e726). +### Fog (EC2, Openstack and friends) +chef-metal also comes with a [Fog](http://fog.io/) provisioner that handles provisioning to Openstack, Rackspace, Amazon's EC2 and other cloud drivers. Before you begin, you will need to put your AWS credentials in ~/.aws/config in the format [mentioned in Option 1 here](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#d0e726). There are other ways to specify your credentials, but this is the standard one for the Amazon CLI. + Once your credentials are in, basic usage looks like this: ``` -chef-client -z -o myapp::ec2,myapp::small +export CHEF_DRIVER=fog:AWS +chef-client -z simple.rb ``` -The provisioner definition in `myapp::ec2` looks like this: +Other valid URLs include `fog:AWS:myprofilename` and `fog:AWS:profilename:us-west-2`. -```ruby -ec2testdir = File.expand_path('~/ec2test') +Most Chef Metal drivers try hard to provide reasonable defaults so you can get started easily. Once you have specified your credentials, AMIs and other things are chosen for you. -directory ec2testdir +You will usually want to create or input a custom key pair for bootstrap. To customize, specify keys and AMI and other options, you can make recipes like this: -with_fog_ec2_provisioner # :driver => 'AWS' +```ruby +require 'chef_metal_fog' -with_provisioner_options :image_id => 'ami-5ee70037' +fog_key_pair 'my_bootstrap_key' -fog_key_pair 'me' do - private_key_path "#{ec2testdir}/me" - public_key_path "#{ec2testdir}/me.pub" -end +with_machine_options :bootstrap_options => { + :key_name => 'my_bootstrap_key', + :image_id => 'ami-59a4a230', + :flavor_id => 't1.micro' +} ``` -`with_fog_ec2_provisioner` tells chef-metal to use the Fog provisioner against EC2. If you specify your credentials in `~/.aws/config`, you don't *have* to specify anything else; it will use the Fog defaults. You may pass a hash of parameters to `with_fog_ec2_provisioner` that is described [here](https://github.com/opscode/chef-metal/blob/master/lib/chef_metal/provisioner/fog_provisioner.rb#L21-L32). +`fog_key_pair` creates a new key pair (if the files do not already exist) and uploads it to AWS (it will toss an error if the key pair already exists and does not match). By default, `fog_key_pair` will look for matching key files in .chef/keys, ~/.chef/keys and ~/.ssh. If it does not find one, it will place the key in `.chef/keys`. You can override this path in fog_key_pair, but if you do, you will want to modify `private_key_paths` in your configuration to match. -`fog_key_pair` creates a new key pair (if the files do not already exist) and automatically tells the Provisioner to use it to bootstrap subsequent machines. The private/public key pair will be automatically authorized to log on to the instance on first boot. +`with_machine_options` specifies machine_options that will be applied to any `machine` resources chef-client encounters. -To pass options like ami, you can say something like this: +You will notice that we are still using `simple.rb` here. Machine definitions are generally driver-independent. This is an important feature that allows you to spin up your clusters in different places to create staging, test or miniature dev environments. +### Pointing Boxes at Chef Servers + +By default, Chef Metal 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: + ```ruby -with_provisioner_options :image_id => 'ami-5ee70037' +with_chef_local_server :chef_repo_path => '~/repo' ``` -If you need to pass bootstrapping options on a per-machine basis, you can do that as well by doing something like the following: +`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. +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 will correctly create a client for the chef server on instance using your knife.rb configuration: + ```ruby -machine "Ubuntu_64bit" do - action :create - provisioner_options 'bootstrap_options' => { - 'image_id' => 'ami-59a4a230', - 'flavor_id' => 't1.micro' - } -end +with_chef_server "https://chef-server.example.org", + :client_name => Chef::Config[:node_name], + :signing_key_filename => Chef::Config[:client_key] ``` -You will notice that we are still using `myapp::small` here. Machine definitions are generally provisioner-independent. This is an important feature that allows you to spin up your clusters in different places to create staging, test or miniature dev environments. +Kitchen +------- +Chef Metal also works with Test Kitchen, allowing you to test entire clusters, not just machines! The repository for the kitchen-metal gem is https://github.com/doubt72/kitchen-metal. + +Documentation +------------- +* [Configuration](https://github.com/opscode/chef-metal/blob/master/docs/configuration.md#configuring-and-using-metal-drivers) +* [Writing Drivers](https://github.com/opscode/chef-metal/blob/master/docs/building_drivers.md#writing-drivers) +* [Embedding](https://github.com/opscode/chef-metal/blob/master/docs/embedding.md) + Bugs and The Plan ----------------- -It's early days. *Please* submit bugs at https://github.com/opscode/chef-metal/issues, contact jkeiser on Twitter at @jkeiser2, email at jkeiser@opscode.com +Please submit bugs, gripes and feature requests at [https://github.com/opscode/chef-metal/issues](https://twitter.com/jkeiser2), contact jkeiser on Twitter at @jkeiser2, email at [jkeiser@getchef.com](mailto:jkeiser@getchef.com) -If you are interested in the Plan for Chef Metal, you can peruse our [Trello board](https://trello.com/b/GcSzW0GM/chef-metal)! Please add suggestions there, vote or comment on issues that are important to you, and feel free to contribute by picking up a card. Chat with me (jkeiser@opscode.com) if you would like some context on how to go about implementing a card, or just go hog wild and submit a PR :) +To contribute, just make a PR in the appropriate repo--also, make sure you've [signed the Chef Contributor License Agreement](https://secure.echosign.com/public/hostedForm?formid=PJIF5694K6L) (quick couple of minutes online), since this is going into core Chef eventually. It takes some time to process, so if you've just done it, let me know in the PR :) If you already signed this for a Chef contribution, you don't need to do so again--if you're not sure, you can check for your name [here](https://wiki.opscode.com/display/chef/Approved+Contributors)!