From 5ce2af31b17165faf47a4847ca0bb03797fe7648 Mon Sep 17 00:00:00 2001 From: paulczar Date: Sun, 17 Nov 2013 15:05:36 -0600 Subject: [PATCH] Vagrant support --- .gitignore | 3 ++ README.md | 34 ++++++++++++ Vagrantfile | 87 ++++++++++++++++++++++++++++++ environments/vagrant_allinone.json | 49 +++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 Vagrantfile create mode 100644 environments/vagrant_allinone.json diff --git a/.gitignore b/.gitignore index 3cffa46c..c1b8a306 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ metadata.json .chef .swp cookbooks.tgz +Berksfile +Berksfile.lock +openrc diff --git a/README.md b/README.md index 3e3236b0..b1ba5047 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,40 @@ Ensure you have [registered](http://wiki.opscode.com/display/chef/Cookbook+Fast+ `...` `knife node run_list add nodeN 'role[single-compute]'` +## Testing ### + +#### Vagrant #### + +Requirements: + +* Vagrant >= 1.3.0 - http://downloads.vagrantup.com/ +* VirtualBox - https://www.virtualbox.org/wiki/Downloads +* Vagrant Plugins + + vagrant plugin install vagrant-omnibus + vagrant plugin install vagrant-chef-zero + vagrant plugin install vagrant-berkshelf + +* rcbops repo + + git clone --recursive git@github.com:rcbops/chef-cookbooks.git + +* Launch + + vagrant up ubuntu1204 + +* Test + + source openrc + nova boot --image cirros-image --flavor 1 Test + nova list + ping 192.168.1.2 + +Things you should know about + +* Chef Environment - `environments/vagrant_allinone.json` +* Berkshelf - Vagrant will create a berkshelf file based on the contents of `.gitmodules` and `cookbooks` + ## Custom template banners ## diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..cd4343f8 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,87 @@ +# make me a Berksfile from hints in .gitsubmodule +if ! File.exist?('Berksfile') or ENV['NEWBERKS'] + puts "looks like you need a Berksfile ... Generating one now." + Berksfile = [] + File.open(".gitmodules", "r").each_line do |line| + if match = /submodule "(.*?)\/(.*?)"/.match(line) and File.exist?("#{match[1]}/#{match[2]}") + Berksfile << "cookbook '#{match[2]}', path: '#{match[1]}/#{match[2]}'" + end + end + File.open("Berksfile", 'w') { |file| file.write(Berksfile.join("\n")) } +end + +Vagrant.require_plugin "vagrant-berkshelf" +Vagrant.require_plugin "vagrant-chef-zero" +Vagrant.require_plugin "vagrant-omnibus" + +Vagrant.configure("2") do |config| + # Berkshelf plugin configuration + config.berkshelf.enabled = true + + # Chef-Zero plugin configuration + config.chef_zero.enabled = true + config.chef_zero.chef_repo_path = "." + + # Omnibus plugin configuration + config.omnibus.chef_version = :latest + + # Port forwarding rules, for access to openstack services + config.vm.network "forwarded_port", guest: 443, host: 8443 # dashboard-ssl + config.vm.network "forwarded_port", guest: 4000, host: 4000 # chef-zero + config.vm.network "forwarded_port", guest: 8773, host: 8773 # compute-ec2-api + config.vm.network "forwarded_port", guest: 8774, host: 8774 # compute-api + + # OpenStack-related settings + config.vm.network "private_network", ip: "192.168.100.60" + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--cpus", 2] + vb.customize ["modifyvm", :id, "--memory", 2048] + vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] + end + + # Ubuntu 12.04 Config + config.vm.define :ubuntu1204 do |ubuntu1204| + ubuntu1204.vm.hostname = "openstack" + ubuntu1204.vm.box = "opscode-ubuntu-12.04" + ubuntu1204.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box" + ubuntu1204.vm.provision :chef_client do |chef| + chef.environment = "vagrant-allinone" + chef.run_list = [ "recipe[apt::cacher-client]", "role[allinone]" ] + end + ubuntu1204.vm.provision :shell, :inline => <<-SCRIPT + cp /root/openrc /vagrant/openrc + chown vagrant /vagrant/openrc + SCRIPT + end + + # Ubuntu 13.04 Config + config.vm.define :ubuntu1304 do |ubuntu1304| + ubuntu1304.vm.hostname = "openstack" + ubuntu1304.vm.box = "opscode-ubuntu-13.04" + ubuntu1304.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-13.04_provisionerless.box" + ubuntu1304.vm.provision :chef_client do |chef| + chef.environment = "vagrant-allinone" + chef.run_list = [ "recipe[apt::cacher-client]", "role[allinone]" ] + end + ubuntu1304.vm.provision :shell, :inline => <<-SCRIPT + cp /root/openrc /vagrant/openrc + chown vagrant /vagrant/openrc + SCRIPT + end + + # Centos 6.4 Config + config.vm.define :centos64 do |centos64| + centos64.vm.hostname = "openstack" + centos64.vm.box = "opscode-centos-6.4" + centos64.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box" + centos64.vm.provision :chef_client do |chef| + chef.environment = "vagrant-allinone" + chef.run_list = [ "role[allinone]" ] + end + centos64.vm.provision :shell, :inline => <<-SCRIPT + cp /root/openrc /vagrant/openrc + chown vagrant /vagrant/openrc + SCRIPT + end + +end diff --git a/environments/vagrant_allinone.json b/environments/vagrant_allinone.json new file mode 100644 index 00000000..3a54db00 --- /dev/null +++ b/environments/vagrant_allinone.json @@ -0,0 +1,49 @@ +{ + "name": "vagrant-allinone", + "description": "Chef-server example environment", + "cookbook_versions": { + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + }, + "override_attributes": { + "developer_mode": false, + "enable_testing_repos": false, + "monitoring" : { + "metric_provider" : "collectd", + "procmon_provider" : "monit" + }, + "glance": { + "image_upload": true, + "images": ["cirros"] + }, + "nova": { + "ratelimit" : { + "api" : { "enabled" : true }, + "volume" : { "enabled" : true } + }, + "libvirt": { "virt_type": "qemu" }, + "networks": { + "public": { + "label": "public", + "ipv4_cidr": "192.168.100.0/24", + "bridge": "br100", + "bridge_dev": "eth1", + "dns1": "8.8.8.8", + "dns2": "8.8.4.4" + } + } + }, + "mysql": { + "allow_remote_root": true, + "root_network_acl": "%" + }, + "osops_networks": { + "nova": "192.168.100.0/24", + "public": "192.168.100.0/24", + "management": "192.168.100.0/24" + }, + "package_component": "havana" + } +}