fixed-vagrant 0.7.4.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +272 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/Rakefile +22 -0
- data/bin/vagrant +22 -0
- data/config/default.rb +39 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.ppk +26 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +42 -0
- data/lib/vagrant/action.rb +134 -0
- data/lib/vagrant/action/box.rb +11 -0
- data/lib/vagrant/action/box/destroy.rb +21 -0
- data/lib/vagrant/action/box/download.rb +72 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +55 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +124 -0
- data/lib/vagrant/action/builtin.rb +104 -0
- data/lib/vagrant/action/env.rb +7 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +50 -0
- data/lib/vagrant/action/general.rb +8 -0
- data/lib/vagrant/action/general/package.rb +109 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +31 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +30 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
- data/lib/vagrant/action/vm/customize.rb +21 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +52 -0
- data/lib/vagrant/action/vm/forward_ports.rb +134 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +29 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +35 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +139 -0
- data/lib/vagrant/action/vm/nfs.rb +159 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
- data/lib/vagrant/action/vm/provision.rb +41 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +70 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +79 -0
- data/lib/vagrant/box.rb +90 -0
- data/lib/vagrant/box_collection.rb +53 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command.rb +25 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +107 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +17 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +42 -0
- data/lib/vagrant/command/ssh_config.rb +26 -0
- data/lib/vagrant/command/status.rb +22 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +19 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +123 -0
- data/lib/vagrant/config/base.rb +85 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +33 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +16 -0
- data/lib/vagrant/config/vm.rb +137 -0
- data/lib/vagrant/config/vm/provisioner.rb +56 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +70 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +23 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +64 -0
- data/lib/vagrant/environment.rb +392 -0
- data/lib/vagrant/errors.rb +332 -0
- data/lib/vagrant/hosts.rb +8 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +78 -0
- data/lib/vagrant/hosts/bsd.rb +52 -0
- data/lib/vagrant/hosts/linux.rb +47 -0
- data/lib/vagrant/plugin.rb +57 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +63 -0
- data/lib/vagrant/provisioners/chef.rb +130 -0
- data/lib/vagrant/provisioners/chef_server.rb +103 -0
- data/lib/vagrant/provisioners/chef_solo.rb +142 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +52 -0
- data/lib/vagrant/ssh.rb +173 -0
- data/lib/vagrant/ssh/session.rb +125 -0
- data/lib/vagrant/systems.rb +11 -0
- data/lib/vagrant/systems/base.rb +87 -0
- data/lib/vagrant/systems/debian.rb +36 -0
- data/lib/vagrant/systems/freebsd.rb +84 -0
- data/lib/vagrant/systems/gentoo.rb +27 -0
- data/lib/vagrant/systems/linux.rb +83 -0
- data/lib/vagrant/systems/linux/config.rb +21 -0
- data/lib/vagrant/systems/linux/error.rb +9 -0
- data/lib/vagrant/systems/redhat.rb +39 -0
- data/lib/vagrant/systems/solaris.rb +62 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +69 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +25 -0
- data/lib/vagrant/util/platform.rb +65 -0
- data/lib/vagrant/util/resource_logger.rb +63 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +177 -0
- data/templates/chef_server_client.erb +18 -0
- data/templates/chef_solo_solo.erb +19 -0
- data/templates/commands/init/Vagrantfile.erb +82 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +535 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +8 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +9 -0
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +26 -0
- data/test/vagrant/action/box/destroy_test.rb +18 -0
- data/test/vagrant/action/box/download_test.rb +125 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/vagrant/action/box/verify_test.rb +30 -0
- data/test/vagrant/action/builder_test.rb +203 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +27 -0
- data/test/vagrant/action/general/package_test.rb +268 -0
- data/test/vagrant/action/general/validate_test.rb +31 -0
- data/test/vagrant/action/vm/boot_test.rb +66 -0
- data/test/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +30 -0
- data/test/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/vagrant/action/vm/export_test.rb +107 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +194 -0
- data/test/vagrant/action/vm/halt_test.rb +79 -0
- data/test/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/vagrant/action/vm/import_test.rb +66 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +36 -0
- data/test/vagrant/action/vm/network_test.rb +286 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/provision_test.rb +90 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +139 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action/warden_test.rb +119 -0
- data/test/vagrant/action_test.rb +89 -0
- data/test/vagrant/box_collection_test.rb +45 -0
- data/test/vagrant/box_test.rb +74 -0
- data/test/vagrant/cli_test.rb +35 -0
- data/test/vagrant/command/base_test.rb +23 -0
- data/test/vagrant/command/group_base_test.rb +15 -0
- data/test/vagrant/command/helpers_test.rb +88 -0
- data/test/vagrant/command/package_test.rb +27 -0
- data/test/vagrant/config/base_test.rb +52 -0
- data/test/vagrant/config/error_recorder_test.rb +18 -0
- data/test/vagrant/config/ssh_test.rb +12 -0
- data/test/vagrant/config/vagrant_test.rb +35 -0
- data/test/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/vagrant/config/vm_test.rb +86 -0
- data/test/vagrant/config_test.rb +162 -0
- data/test/vagrant/data_store_test.rb +77 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +48 -0
- data/test/vagrant/downloaders/http_test.rb +80 -0
- data/test/vagrant/environment_test.rb +508 -0
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +53 -0
- data/test/vagrant/hosts/linux_test.rb +54 -0
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +63 -0
- data/test/vagrant/provisioners/chef_server_test.rb +188 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +219 -0
- data/test/vagrant/provisioners/chef_test.rb +179 -0
- data/test/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/vagrant/provisioners/shell_test.rb +68 -0
- data/test/vagrant/ssh/session_test.rb +40 -0
- data/test/vagrant/ssh_test.rb +342 -0
- data/test/vagrant/systems/base_test.rb +18 -0
- data/test/vagrant/systems/linux_test.rb +114 -0
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +78 -0
- data/test/vagrant/util/retryable_test.rb +50 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/vm_test.rb +291 -0
- data/vagrant.gemspec +36 -0
- metadata +514 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Hosts
|
3
|
+
# Represents a Linux based host, such as Ubuntu.
|
4
|
+
class Linux < Base
|
5
|
+
include Util
|
6
|
+
include Util::Retryable
|
7
|
+
|
8
|
+
def nfs?
|
9
|
+
retryable(:tries => 10, :on => TypeError) do
|
10
|
+
# Check procfs to see if NFSd is a supported filesystem
|
11
|
+
system("cat /proc/filesystems | grep nfsd > /dev/null 2>&1")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def nfs_export(ip, folders)
|
16
|
+
output = TemplateRenderer.render('nfs/exports_linux',
|
17
|
+
:uuid => env.vm.uuid,
|
18
|
+
:ip => ip,
|
19
|
+
:folders => folders)
|
20
|
+
|
21
|
+
env.ui.info I18n.t("vagrant.hosts.linux.nfs_export.prepare")
|
22
|
+
sleep 0.5
|
23
|
+
|
24
|
+
output.split("\n").each do |line|
|
25
|
+
# This should only ask for administrative permission once, even
|
26
|
+
# though its executed in multiple subshells.
|
27
|
+
system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"])
|
28
|
+
end
|
29
|
+
|
30
|
+
# We run restart here instead of "update" just in case nfsd
|
31
|
+
# is not starting
|
32
|
+
system("sudo /etc/init.d/nfs-kernel-server restart")
|
33
|
+
end
|
34
|
+
|
35
|
+
def nfs_cleanup
|
36
|
+
return if !File.exist?("/etc/exports")
|
37
|
+
system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
|
38
|
+
|
39
|
+
if $?.to_i == 0
|
40
|
+
# Use sed to just strip out the block of code which was inserted
|
41
|
+
# by Vagrant
|
42
|
+
system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -ibak /etc/exports")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
# Represents a single plugin and also manages loading plugins from
|
5
|
+
# RubyGems. If a plugin has a `vagrant_init.rb` file somewhere on its
|
6
|
+
# load path, then this class will find it and load it. For logging purposes
|
7
|
+
# (for debugging), the list of loaded plugins is stored in the {plugins}
|
8
|
+
# array.
|
9
|
+
class Plugin
|
10
|
+
# The array of loaded plugins.
|
11
|
+
@@plugins = []
|
12
|
+
|
13
|
+
# The gemspec of this plugin. This is an actual gemspec object.
|
14
|
+
attr_reader :gemspec
|
15
|
+
|
16
|
+
# The path to the `vagrant_init.rb` file which was loaded for this plugin.
|
17
|
+
attr_reader :file
|
18
|
+
|
19
|
+
# Loads all the plugins for Vagrant. Plugins are currently
|
20
|
+
# gems which have a "vagrant_init.rb" somewhere on their
|
21
|
+
# load path. This file is loaded to kick off the load sequence
|
22
|
+
# for that plugin.
|
23
|
+
def self.load!
|
24
|
+
# Stupid hack since Rails 2.3.x overrides Gem.source_index with their
|
25
|
+
# own incomplete replacement which causes issues.
|
26
|
+
index = Gem.source_index
|
27
|
+
index = [index.installed_source_index, index.vendor_source_index] if defined?(Rails::VendorGemSourceIndex) && index.is_a?(Rails::VendorGemSourceIndex)
|
28
|
+
|
29
|
+
# Look for a vagrant_init.rb in all the gems, but only the
|
30
|
+
# latest version of the gems.
|
31
|
+
[index].flatten.each do |source|
|
32
|
+
source.latest_specs.each do |spec|
|
33
|
+
file = Gem.searcher.matching_files(spec, "vagrant_init.rb").first
|
34
|
+
next if !file
|
35
|
+
|
36
|
+
@@plugins << new(spec, file)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the array of plugins which are currently loaded by
|
42
|
+
# Vagrant.
|
43
|
+
#
|
44
|
+
# @return [Array]
|
45
|
+
def self.plugins; @@plugins; end
|
46
|
+
|
47
|
+
# Initializes a new plugin, given a Gemspec and the path to the
|
48
|
+
# gem's `vagrant_init.rb` file. This should never be called manually.
|
49
|
+
# Instead {load!} creates all the instances.
|
50
|
+
def initialize(spec, file)
|
51
|
+
@gemspec = spec
|
52
|
+
@file = file
|
53
|
+
|
54
|
+
load file
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# These aren't autoloaded because they have to register things such
|
2
|
+
# as configuration classes right away with Vagrant.
|
3
|
+
require 'vagrant/provisioners/base'
|
4
|
+
require 'vagrant/provisioners/chef'
|
5
|
+
require 'vagrant/provisioners/chef_server'
|
6
|
+
require 'vagrant/provisioners/chef_solo'
|
7
|
+
require 'vagrant/provisioners/puppet'
|
8
|
+
require 'vagrant/provisioners/puppet_server'
|
9
|
+
require 'vagrant/provisioners/shell'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Provisioners
|
3
|
+
# The base class for a "provisioner." A provisioner is responsible for
|
4
|
+
# provisioning a Vagrant system. This has been abstracted out to provide
|
5
|
+
# support for multiple solutions such as Chef Solo, Chef Client, and
|
6
|
+
# Puppet.
|
7
|
+
class Base
|
8
|
+
include Vagrant::Util
|
9
|
+
|
10
|
+
# The environment which provisioner is running in. This is a
|
11
|
+
# {Vagrant::Action::Environment}
|
12
|
+
attr_reader :action_env
|
13
|
+
|
14
|
+
# The configuration for this provisioner. This will be an instance of
|
15
|
+
# the `Config` class which is part of the provisioner.
|
16
|
+
attr_reader :config
|
17
|
+
|
18
|
+
# Registers a provisioner with a given shortcut. This allows that provisioner
|
19
|
+
# to be referenced with the shortcut.
|
20
|
+
#
|
21
|
+
# @param [Symbol] shortcut
|
22
|
+
def self.register(shortcut)
|
23
|
+
registered[shortcut] = self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the provisioner associated with the given shortcut.
|
27
|
+
def self.registered
|
28
|
+
@@registered ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(env, config)
|
32
|
+
@action_env = env
|
33
|
+
@config = config
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the actual {Vagrant::Environment} which this provisioner
|
37
|
+
# represents.
|
38
|
+
#
|
39
|
+
# @return [Vagrant::Environment]
|
40
|
+
def env
|
41
|
+
action_env.env
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the VM which this provisioner is working on.
|
45
|
+
#
|
46
|
+
# @return [Vagrant::VM]
|
47
|
+
def vm
|
48
|
+
env.vm
|
49
|
+
end
|
50
|
+
|
51
|
+
# This is the method called to "prepare" the provisioner. This is called
|
52
|
+
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
|
53
|
+
# This can be used to setup shared folders, forward ports, etc. Whatever is
|
54
|
+
# necessary on a "meta" level.
|
55
|
+
def prepare; end
|
56
|
+
|
57
|
+
# This is the method called to provision the system. This method
|
58
|
+
# is expected to do whatever necessary to provision the system (create files,
|
59
|
+
# SSH, etc.)
|
60
|
+
def provision!; end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Provisioners
|
3
|
+
# This class is a base class where the common functionality shared between
|
4
|
+
# chef-solo and chef-client provisioning are stored. This is **not an actual
|
5
|
+
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
|
6
|
+
class Chef < Base
|
7
|
+
def prepare
|
8
|
+
raise ChefError, :invalid_provisioner
|
9
|
+
end
|
10
|
+
|
11
|
+
def verify_binary(binary)
|
12
|
+
vm.ssh.execute do |ssh|
|
13
|
+
# Checks for the existence of chef binary and error if it
|
14
|
+
# doesn't exist.
|
15
|
+
ssh.sudo!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def chown_provisioning_folder
|
20
|
+
vm.ssh.execute do |ssh|
|
21
|
+
ssh.sudo!("mkdir -p #{config.provisioning_path}")
|
22
|
+
ssh.sudo!("chown #{env.config.ssh.username} #{config.provisioning_path}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_config(template, filename, template_vars)
|
27
|
+
config_file = TemplateRenderer.render(template, {
|
28
|
+
:log_level => config.log_level.to_sym,
|
29
|
+
:http_proxy => config.http_proxy,
|
30
|
+
:http_proxy_user => config.http_proxy_user,
|
31
|
+
:http_proxy_pass => config.http_proxy_pass,
|
32
|
+
:https_proxy => config.https_proxy,
|
33
|
+
:https_proxy_user => config.https_proxy_user,
|
34
|
+
:https_proxy_pass => config.https_proxy_pass,
|
35
|
+
:no_proxy => config.no_proxy
|
36
|
+
}.merge(template_vars))
|
37
|
+
|
38
|
+
vm.ssh.upload!(StringIO.new(config_file), File.join(config.provisioning_path, filename))
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_json
|
42
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.json")
|
43
|
+
|
44
|
+
# Set up initial configuration
|
45
|
+
data = {
|
46
|
+
:config => env.config.to_hash,
|
47
|
+
:directory => env.config.vm.shared_folders["v-root"][:guestpath],
|
48
|
+
}
|
49
|
+
|
50
|
+
# And wrap it under the "vagrant" namespace
|
51
|
+
data = { :vagrant => data }
|
52
|
+
|
53
|
+
# Merge with the "extra data" which isn't put under the
|
54
|
+
# vagrant namespace by default
|
55
|
+
data.merge!(config.json)
|
56
|
+
|
57
|
+
json = data.to_json
|
58
|
+
|
59
|
+
vm.ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Chef < Base
|
64
|
+
class ChefError < Errors::VagrantError
|
65
|
+
error_namespace("vagrant.provisioners.chef")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Chef < Base
|
70
|
+
# This is the configuration which is available through `config.chef`
|
71
|
+
class Config < Vagrant::Config::Base
|
72
|
+
# Shared config
|
73
|
+
attr_accessor :node_name
|
74
|
+
attr_accessor :provisioning_path
|
75
|
+
attr_accessor :log_level
|
76
|
+
attr_accessor :json
|
77
|
+
attr_accessor :http_proxy
|
78
|
+
attr_accessor :http_proxy_user
|
79
|
+
attr_accessor :http_proxy_pass
|
80
|
+
attr_accessor :https_proxy
|
81
|
+
attr_accessor :https_proxy_user
|
82
|
+
attr_accessor :https_proxy_pass
|
83
|
+
attr_accessor :no_proxy
|
84
|
+
|
85
|
+
def initialize
|
86
|
+
@provisioning_path = "/tmp/vagrant-chef"
|
87
|
+
@log_level = :info
|
88
|
+
@json = { :instance_role => "vagrant" }
|
89
|
+
@http_proxy = nil
|
90
|
+
@http_proxy_user = nil
|
91
|
+
@http_proxy_pass = nil
|
92
|
+
@https_proxy = nil
|
93
|
+
@https_proxy_user = nil
|
94
|
+
@https_proxy_pass = nil
|
95
|
+
@no_proxy = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the run list for the provisioning
|
99
|
+
def run_list
|
100
|
+
json[:run_list] ||= []
|
101
|
+
end
|
102
|
+
|
103
|
+
# Sets the run list to the specified value
|
104
|
+
def run_list=(value)
|
105
|
+
json[:run_list] = value
|
106
|
+
end
|
107
|
+
|
108
|
+
# Adds a recipe to the run list
|
109
|
+
def add_recipe(name)
|
110
|
+
name = "recipe[#{name}]" unless name =~ /^recipe\[(.+?)\]$/
|
111
|
+
run_list << name
|
112
|
+
end
|
113
|
+
|
114
|
+
# Adds a role to the run list
|
115
|
+
def add_role(name)
|
116
|
+
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/
|
117
|
+
run_list << name
|
118
|
+
end
|
119
|
+
|
120
|
+
def instance_variables_hash
|
121
|
+
# Overridden so that the 'json' key could be removed, since its just
|
122
|
+
# merged into the config anyways
|
123
|
+
result = super
|
124
|
+
result.delete("json")
|
125
|
+
result
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Provisioners
|
5
|
+
# This class implements provisioning via chef-client, allowing provisioning
|
6
|
+
# with a chef server.
|
7
|
+
class ChefServer < Chef
|
8
|
+
register :chef_server
|
9
|
+
|
10
|
+
class Config < Chef::Config
|
11
|
+
attr_accessor :chef_server_url
|
12
|
+
attr_accessor :validation_key_path
|
13
|
+
attr_accessor :validation_client_name
|
14
|
+
attr_accessor :client_key_path
|
15
|
+
attr_accessor :file_cache_path
|
16
|
+
attr_accessor :file_backup_path
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
|
21
|
+
@validation_client_name = "chef-validator"
|
22
|
+
@client_key_path = "/etc/chef/client.pem"
|
23
|
+
@file_cache_path = "/srv/chef/file_store"
|
24
|
+
@file_backup_path = "/srv/chef/cache"
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate(errors)
|
28
|
+
super
|
29
|
+
|
30
|
+
errors.add(I18n.t("vagrant.config.chef.server_url_empty")) if !chef_server_url || chef_server_url.strip == ""
|
31
|
+
errors.add(I18n.t("vagrant.config.chef.validation_key_path")) if !validation_key_path
|
32
|
+
errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if json[:run_list] && run_list.empty?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def prepare
|
37
|
+
raise ChefError, :server_validation_key_required if config.validation_key_path.nil?
|
38
|
+
raise ChefError, :server_validation_key_doesnt_exist if !File.file?(validation_key_path)
|
39
|
+
raise ChefError, :server_url_required if config.chef_server_url.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def provision!
|
43
|
+
verify_binary("chef-client")
|
44
|
+
chown_provisioning_folder
|
45
|
+
create_client_key_folder
|
46
|
+
upload_validation_key
|
47
|
+
setup_json
|
48
|
+
setup_server_config
|
49
|
+
run_chef_client
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_client_key_folder
|
53
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
54
|
+
path = Pathname.new(config.client_key_path)
|
55
|
+
|
56
|
+
vm.ssh.execute do |ssh|
|
57
|
+
ssh.sudo!("mkdir -p #{path.dirname}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def upload_validation_key
|
62
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")
|
63
|
+
vm.ssh.upload!(validation_key_path, guest_validation_key_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_server_config
|
67
|
+
setup_config("chef_server_client", "client.rb", {
|
68
|
+
:node_name => config.node_name,
|
69
|
+
:chef_server_url => config.chef_server_url,
|
70
|
+
:validation_client_name => config.validation_client_name,
|
71
|
+
:validation_key => guest_validation_key_path,
|
72
|
+
:client_key => config.client_key_path,
|
73
|
+
:file_cache_path => config.file_cache_path,
|
74
|
+
:file_backup_path => config.file_backup_path
|
75
|
+
})
|
76
|
+
end
|
77
|
+
|
78
|
+
def run_chef_client
|
79
|
+
commands = ["cd #{config.provisioning_path}",
|
80
|
+
"chef-client -c client.rb -j dna.json"]
|
81
|
+
|
82
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
|
83
|
+
vm.ssh.execute do |ssh|
|
84
|
+
ssh.sudo!(commands) do |channel, type, data|
|
85
|
+
if type == :exit_status
|
86
|
+
ssh.check_exit_status(data, commands)
|
87
|
+
else
|
88
|
+
env.ui.info("#{data}: #{type}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def validation_key_path
|
95
|
+
File.expand_path(config.validation_key_path, env.root_path)
|
96
|
+
end
|
97
|
+
|
98
|
+
def guest_validation_key_path
|
99
|
+
File.join(config.provisioning_path, "validation.pem")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Provisioners
|
3
|
+
# This class implements provisioning via chef-solo.
|
4
|
+
class ChefSolo < Chef
|
5
|
+
register :chef_solo
|
6
|
+
|
7
|
+
class Config < Chef::Config
|
8
|
+
attr_accessor :cookbooks_path
|
9
|
+
attr_accessor :roles_path
|
10
|
+
attr_accessor :recipe_url
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
|
15
|
+
@cookbooks_path = ["cookbooks", [:vm, "cookbooks"]]
|
16
|
+
@roles_path = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate(errors)
|
20
|
+
super
|
21
|
+
|
22
|
+
errors.add(I18n.t("vagrant.config.chef.cookbooks_path_empty")) if !cookbooks_path || [cookbooks_path].flatten.empty?
|
23
|
+
errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if !json[:run_list] || run_list.empty?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def prepare
|
28
|
+
share_cookbook_folders
|
29
|
+
share_role_folders
|
30
|
+
end
|
31
|
+
|
32
|
+
def provision!
|
33
|
+
verify_binary("chef-solo")
|
34
|
+
chown_provisioning_folder
|
35
|
+
setup_json
|
36
|
+
setup_solo_config
|
37
|
+
run_chef_solo
|
38
|
+
end
|
39
|
+
|
40
|
+
def share_cookbook_folders
|
41
|
+
host_cookbook_paths.each_with_index do |cookbook, i|
|
42
|
+
env.config.vm.share_folder("v-csc-#{i}", cookbook_path(i), cookbook)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def share_role_folders
|
47
|
+
host_role_paths.each_with_index do |role, i|
|
48
|
+
env.config.vm.share_folder("v-csr-#{i}", role_path(i), role)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_solo_config
|
53
|
+
setup_config("chef_solo_solo", "solo.rb", {
|
54
|
+
:node_name => config.node_name,
|
55
|
+
:provisioning_path => config.provisioning_path,
|
56
|
+
:cookbooks_path => cookbooks_path,
|
57
|
+
:recipe_url => config.recipe_url,
|
58
|
+
:roles_path => roles_path,
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_chef_solo
|
63
|
+
commands = ["cd #{config.provisioning_path}", "chef-solo -c solo.rb -j dna.json"]
|
64
|
+
|
65
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
|
66
|
+
vm.ssh.execute do |ssh|
|
67
|
+
ssh.sudo!(commands) do |channel, type, data|
|
68
|
+
if type == :exit_status
|
69
|
+
ssh.check_exit_status(data, commands)
|
70
|
+
else
|
71
|
+
env.ui.info("#{data}: #{type}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def host_folder_paths(paths)
|
78
|
+
# Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"]
|
79
|
+
# into a proper array representation.
|
80
|
+
paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol)
|
81
|
+
|
82
|
+
paths.inject([]) do |acc, path|
|
83
|
+
path = [:host, path] if !path.is_a?(Array)
|
84
|
+
type, path = path
|
85
|
+
|
86
|
+
acc << File.expand_path(path, env.root_path) if type == :host
|
87
|
+
acc
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def folder_path(*args)
|
92
|
+
File.join(config.provisioning_path, args.join("-"))
|
93
|
+
end
|
94
|
+
|
95
|
+
def folders_path(folders, folder)
|
96
|
+
# Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"]
|
97
|
+
# into a proper array representation.
|
98
|
+
folders = [folders] if folders.is_a?(String) || folders.first.is_a?(Symbol)
|
99
|
+
|
100
|
+
# Convert each path to the proper absolute path depending on if the path
|
101
|
+
# is a host path or a VM path
|
102
|
+
result = []
|
103
|
+
folders.each_with_index do |path, i|
|
104
|
+
path = [:host, path] if !path.is_a?(Array)
|
105
|
+
type, path = path
|
106
|
+
|
107
|
+
result << folder_path(folder, i) if type == :host
|
108
|
+
result << folder_path(path) if type == :vm
|
109
|
+
end
|
110
|
+
|
111
|
+
# We're lucky that ruby's string and array syntax for strings is the
|
112
|
+
# same as JSON, so we can just convert to JSON here and use that
|
113
|
+
result = result[0].to_s if result.length == 1
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
def host_cookbook_paths
|
118
|
+
host_folder_paths(config.cookbooks_path)
|
119
|
+
end
|
120
|
+
|
121
|
+
def host_role_paths
|
122
|
+
host_folder_paths(config.roles_path)
|
123
|
+
end
|
124
|
+
|
125
|
+
def cookbook_path(i)
|
126
|
+
folder_path("cookbooks", i)
|
127
|
+
end
|
128
|
+
|
129
|
+
def role_path(i)
|
130
|
+
folder_path("roles", i)
|
131
|
+
end
|
132
|
+
|
133
|
+
def cookbooks_path
|
134
|
+
folders_path(config.cookbooks_path, "cookbooks").to_json
|
135
|
+
end
|
136
|
+
|
137
|
+
def roles_path
|
138
|
+
folders_path(config.roles_path, "roles").to_json
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|