chef-boneyard / chef-provisioning-vagrant

Vagrant provisioner for chef-provisioning
Apache License 2.0
22 stars 24 forks source link

machine_batch converge optimization (virtualbox) #11

Open wrightp opened 9 years ago

wrightp commented 9 years ago

The virtualbox provider does not yet support the --parallel option. The :converge action is responsible for also bootstrapping the chef-client which is done serially via vagrant up. If the machines' run lists or recipes have been configured, the vagrant up command will provision those recipes and will converge serially because the ssh transport is not used in this case.

This use case identified a workflow issue. Once all the vms are created and bootstrapped, convergence should fallback to using the ssh transport.

Here's the workaround:

machine_list = ['create-1', 'create-2']

# create and bootstrap vms
machine_batch do
  machines machine_list
end

# :converge_only to force ssh transport
machine_batch do
  machine_list.each { |m|
    machine m do
      recipe 'build-essential'
    end
  }
  action :converge_only
end
cheeseplus commented 9 years ago

Setting converge_only as per the example here https://gist.github.com/patrick-wright/7bf6e7345eb6d93fbeac#comment-1340092 doesn't actually seem to do anything but install Chef as it somehow zeroes out the run_list

wrightp commented 9 years ago

@cheeseplus I had the day off but this idea came to me randomly. Could you try this updated version: https://gist.github.com/patrick-wright/7bf6e7345eb6d93fbeac

cheeseplus commented 9 years ago

@patrick-wright while it works it doesn't speed up anything - same results as the initial implementation, serial converging

wrightp commented 9 years ago

Alright. We've tried enough workarounds :) I tried one last thing to isolate the chef-client bootstrap from the machine run lists.

The basic example in the description works. What this recipe is trying to accomplish is not behaving as chef-provisioning intends.

require 'chef/provisioning'

controller_config = <<-ENDCONFIG
  config.vm.box = "centos65"
  config.vm.network "forwarded_port", guest: 443, host: 9443 # dashboard-ssl
  config.vm.network "forwarded_port", guest: 4002, host: 4002
  config.vm.network "forwarded_port", guest: 5000, host: 5000
  config.vm.network "forwarded_port", guest: 8773, host: 8773 # compute-ec2-api
  config.vm.network "forwarded_port", guest: 8774, host: 8774 # compute-api
  config.vm.network "forwarded_port", guest: 35357, host: 35357
  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
    v.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
    v.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end
  config.vm.network "public_network", ip: "192.168.100.60", bridge: 'en0: Wi-Fi (AirPort)'
  config.vm.network "private_network", ip: "192.168.200.60"
ENDCONFIG

with_driver "vagrant:#{File.dirname(__FILE__)}/vms"

# create machine and set converge true to bootstrap client (serially)
machine_batch do
  machine 'controller' do
    machine_options :vagrant_config => controller_config
    converge true
  end

  [ ['compute1', 61], ['compute2', 62], ['compute3', 63] ].each do |name, ip_suff|
    machine name do
      machine_options :vagrant_config => <<-ENDCONFIG
config.vm.box = "centos65"
config.vm.provider "virtualbox" do |v|
  v.memory = 2048
  v.cpus = 2
  v.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
  v.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
  v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
config.vm.network "public_network", ip: "192.168.100.#{ip_suff}", bridge: 'en0: Wi-Fi (AirPort)'
config.vm.network "private_network", ip: "192.168.200.#{ip_suff}"
ENDCONFIG
      converge true 
    end
  end
end

# copy and paste and included run list attributes.  
# This is where I hoped the converge would run in parallel.  It does not :(
 machine_batch do
  machine 'controller' do
    machine_options :vagrant_config => controller_config
    role 'os-compute-single-controller'
    recipe 'openstack-network::identity_registration'
    role 'os-network-dhcp-agent'
    role 'os-network-metadata-agent'
    role 'os-network-server'
    recipe 'openstack-common::openrc'
    chef_environment 'vagrant-multi-nova'
    file '/etc/chef/openstack_data_bag_secret',"#{File.dirname(__FILE__)}/.chef/encrypted_data_bag_secret"
  end

  [ ['compute1', 61], ['compute2', 62], ['compute3', 63] ].each do |name, ip_suff|
    machine name do
      machine_options :vagrant_config => <<-ENDCONFIG
config.vm.box = "centos65"
config.vm.provider "virtualbox" do |v|
  v.memory = 2048
  v.cpus = 2
  v.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
  v.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
  v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
config.vm.network "public_network", ip: "192.168.100.#{ip_suff}", bridge: 'en0: Wi-Fi (AirPort)'
config.vm.network "private_network", ip: "192.168.200.#{ip_suff}"
ENDCONFIG
      role 'os-compute-worker'
      chef_environment 'vagrant-multi-nova'
      file '/etc/chef/openstack_data_bag_secret',"#{File.dirname(__FILE__)}/.chef/encrypted_data_bag_secret"
    end
  end
end
jkeiser commented 9 years ago

@patrick-wright making sure I understand this: the issue is that vagrant up will re-run chef-client on the box?