package 'apache2' do
version '2.0'
end
template '/etc/httpd.conf'
service 'apache2'
machine 'db' do
recipe 'mysql'
end
machine 'web1' do
recipe 'apache'
end
> CHEF_DRIVER=vagrant:~/vms
> chef-client -z cluster.rb
Recipe: talk1::cluster
* machine[db] action create
- run vagrant up db
- write file /etc/chef/client.rb on db
Starting Chef Client, version 11.8.2
Recipe: mysql::default
* file[/etc/mysql.txt] action create - create new file /etc/mysql.txt
Chef Client finished, 1 resources updated
- run 'chef-client' on db
* machine[web1] action create
- run vagrant up web1
- write file /etc/chef/client.rb on web1
- run 'chef-client' on web1
Chef Client finished, 2 resources updated
chef-client
private_key 'crypt'
chef_data_bag_item 'x/y' do
secret_path 'crypt'
end
machine 'mydb' do
file '/etc/crypt', 'crypt'
end
metal login [node] metal execute [node] metal delete [node] metal converge [node]
machine 'db' do
recipe 'mysql'
end
machine 'web' do
recipe 'apache'
end
machine 'web2' do
recipe 'apache'
end
> chef-client -z -o cluster.rb
Recipe: talk1::cluster
* machine[db] action create (up to date)
* machine[web1] action create (up to date)
* machine[web2] action create
- run vagrant up web2
- write file /etc/chef/client.rb on web2
Starting Chef Client, version 11.8.2
Recipe: apache::default
* file[/etc/apache.txt] action create - create new file /etc/apache.txt
Chef Client finished, 1 resources updated
- run 'chef-client' on web2
Chef Client finished, 1 resource updated
CHEF_DRIVER=fog:AWS:default
> chef-client -z cluster.rb
machine 'db' dorecipe 'mysql'
end
machine 'web' do
recipe 'apache'
end
machine 'web2' do
recipe 'apache'
end
1.upto(num_webservers) do
machine "webserver#{i}" do
recipe 'apache'
tag 'webserver'
end
end
search('tags:webserver') do |node|
node.name =~ /^webserver(\d+)$/
if $1.to_i > num_webservers
machine node.name do
action :delete
end
end
end
with_machine_batch 'my_batch'
1.upto(50) do |i|
machine "webserver#{i}" do
recipe 'apache'
end
end
class MyProvisioner < Provisioner
def allocate_machine(ah, machine, options)
id = machine.location['id']
if id
server = lookup_server(id)
else
server = create_server(options) machine.location = {
'id' => server.id
}
end
end
end
machine_options :vagrant_options => { 'vm.box' => 'precise64' },
:vagrant_config => 'config.vm.synced_folder "~/code", "/mnt/code"'
machine_options :bootstrap_options => {
:image_id => 'ami-2f726546',
:flavor_id => 'c1.xlarge'
}
machine 'webserver' do
driver 'fog:GoogleCloud:MyAccount'
recipe 'webserver'
end
with_driver 'fog:AWS:default', :region => 'us-west-1' do
machine 'monitor' do
recipe 'monitor'
end
machine 'another_webserver' do
machine_options :region => 'us-east-1'
recipe 'webserver'
end
end
1.0 Soon.
After 1.0: