vagrant 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGELOG.md +18 -0
  2. data/README.md +1 -1
  3. data/config/default.rb +1 -1
  4. data/lib/vagrant/action/builtin.rb +1 -0
  5. data/lib/vagrant/action/vm.rb +1 -0
  6. data/lib/vagrant/action/vm/host_name.rb +21 -0
  7. data/lib/vagrant/command/ssh_config.rb +5 -0
  8. data/lib/vagrant/config/vm.rb +1 -0
  9. data/lib/vagrant/provisioners.rb +1 -0
  10. data/lib/vagrant/provisioners/chef.rb +3 -3
  11. data/lib/vagrant/provisioners/chef_server.rb +5 -4
  12. data/lib/vagrant/provisioners/chef_solo.rb +3 -3
  13. data/lib/vagrant/provisioners/puppet.rb +5 -4
  14. data/lib/vagrant/provisioners/puppet_server.rb +4 -6
  15. data/lib/vagrant/provisioners/shell.rb +52 -0
  16. data/lib/vagrant/ssh.rb +7 -1
  17. data/lib/vagrant/ssh/session.rb +57 -24
  18. data/lib/vagrant/systems.rb +1 -0
  19. data/lib/vagrant/systems/base.rb +4 -0
  20. data/lib/vagrant/systems/debian.rb +9 -0
  21. data/lib/vagrant/systems/freebsd.rb +84 -0
  22. data/lib/vagrant/systems/gentoo.rb +1 -1
  23. data/lib/vagrant/systems/redhat.rb +11 -3
  24. data/lib/vagrant/version.rb +1 -1
  25. data/lib/vagrant/vm.rb +5 -4
  26. data/templates/locales/en.yml +17 -4
  27. data/templates/ssh_config.erb +1 -1
  28. data/test/vagrant/action/vm/host_name_test.rb +36 -0
  29. data/test/vagrant/provisioners/chef_server_test.rb +3 -3
  30. data/test/vagrant/provisioners/chef_solo_test.rb +2 -2
  31. data/test/vagrant/provisioners/chef_test.rb +3 -3
  32. data/test/vagrant/provisioners/puppet_server_test.rb +5 -6
  33. data/test/vagrant/provisioners/puppet_test.rb +2 -2
  34. data/test/vagrant/provisioners/shell_test.rb +68 -0
  35. data/test/vagrant/ssh_test.rb +1 -0
  36. data/vagrant.gemspec +2 -2
  37. metadata +13 -8
@@ -1,3 +1,21 @@
1
+ ## 0.7.1 (January 28, 2011)
2
+
3
+ - Change error output with references to VirtualBox 3.2 to 4.0.
4
+ - Internal SSH through net-ssh now uses `IdentitiesOnly` thanks to
5
+ upstream net-ssh fix.
6
+ - Fix issue causing warnings to show with `forwardx11` enabled for SSH. [GH-279]
7
+ - FreeBSD support for host only networks, NFS, halting, etc. [GH-275]
8
+ - Make SSH commands which use sudo compatible with sudo < 1.7.0. [GH-278]
9
+ - Fix broken puppet server provisioner which called a nonexistent
10
+ method.
11
+ - Default SSH host changed from `localhost` to `127.0.0.1` since
12
+ `localhost` is not always loopback.
13
+ - New `shell` provisioner which simply uploads and executes a script as
14
+ root on the VM.
15
+ - Gentoo host only networking no longer fails if alrady setup. [GH-286]
16
+ - Set the host name of your guest OS with `config.vm.host_name` [GH-273]
17
+ - `vagrant ssh-config` now outputs the configured `config.ssh.host`
18
+
1
19
  ## 0.7.0 (January 19, 2011)
2
20
 
3
21
  - VirtualBox 4.0 support. Support for VirtualBox 3.2 is _dropped_, since
data/README.md CHANGED
@@ -32,7 +32,7 @@ the box doesn't already exist on your system.
32
32
  ## Getting Started Guide and Video
33
33
 
34
34
  To learn how to build a fully functional rails development environment, view the
35
- [getting started guide](http://vagrantup.com/getting-started/index.html).
35
+ [getting started guide](http://vagrantup.com/docs/getting-started/index.html).
36
36
 
37
37
  There is also a fairly short (12 minute) [getting started video](http://vimeo.com/9976342) which
38
38
  explains how to build a fully functional LAMP development environment, which
@@ -4,7 +4,7 @@ Vagrant::Config.run do |config|
4
4
  config.vagrant.host = :detect
5
5
 
6
6
  config.ssh.username = "vagrant"
7
- config.ssh.host = "localhost"
7
+ config.ssh.host = "127.0.0.1"
8
8
  config.ssh.forwarded_port_key = "ssh"
9
9
  config.ssh.max_tries = 10
10
10
  config.ssh.timeout = 30
@@ -21,6 +21,7 @@ module Vagrant
21
21
  use VM::NFS
22
22
  use VM::ClearSharedFolders
23
23
  use VM::ShareFolders
24
+ use VM::HostName
24
25
  use VM::Network
25
26
  use VM::Boot
26
27
  end)
@@ -15,6 +15,7 @@ module Vagrant
15
15
  autoload :Export, 'vagrant/action/vm/export'
16
16
  autoload :ForwardPorts, 'vagrant/action/vm/forward_ports'
17
17
  autoload :Halt, 'vagrant/action/vm/halt'
18
+ autoload :HostName, 'vagrant/action/vm/host_name'
18
19
  autoload :Import, 'vagrant/action/vm/import'
19
20
  autoload :MatchMACAddress, 'vagrant/action/vm/match_mac_address'
20
21
  autoload :Network, 'vagrant/action/vm/network'
@@ -0,0 +1,21 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class HostName
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @app.call(env)
11
+
12
+ host_name = env["config"].vm.host_name
13
+ if !host_name.nil?
14
+ env.ui.info I18n.t("vagrant.actions.vm.host_name.setting")
15
+ env["vm"].system.change_host_name(host_name)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -9,8 +9,13 @@ module Vagrant
9
9
  vm = target_vms.first
10
10
  raise Errors::VMNotCreatedError if !vm.created?
11
11
 
12
+ # We need to fix the file permissions of the key if they aren't set
13
+ # properly, otherwise if the user attempts to SSH in, it won't work!
14
+ vm.ssh.check_key_permissions(vm.env.config.ssh.private_key_path)
15
+
12
16
  $stdout.puts(Util::TemplateRenderer.render("ssh_config", {
13
17
  :host_key => options[:host] || "vagrant",
18
+ :ssh_host => vm.env.config.ssh.host,
14
19
  :ssh_user => vm.env.config.ssh.username,
15
20
  :ssh_port => vm.ssh.port,
16
21
  :private_key_path => vm.env.config.ssh.private_key_path
@@ -14,6 +14,7 @@ module Vagrant
14
14
  attr_accessor :box_ovf
15
15
  attr_accessor :base_mac
16
16
  attr_accessor :boot_mode
17
+ attr_accessor :host_name
17
18
  attr_reader :forwarded_ports
18
19
  attr_reader :shared_folders
19
20
  attr_reader :network_options
@@ -6,3 +6,4 @@ require 'vagrant/provisioners/chef_server'
6
6
  require 'vagrant/provisioners/chef_solo'
7
7
  require 'vagrant/provisioners/puppet'
8
8
  require 'vagrant/provisioners/puppet_server'
9
+ require 'vagrant/provisioners/shell'
@@ -12,14 +12,14 @@ module Vagrant
12
12
  vm.ssh.execute do |ssh|
13
13
  # Checks for the existence of chef binary and error if it
14
14
  # doesn't exist.
15
- ssh.exec!("sudo -i which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
15
+ ssh.sudo!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
16
16
  end
17
17
  end
18
18
 
19
19
  def chown_provisioning_folder
20
20
  vm.ssh.execute do |ssh|
21
- ssh.exec!("sudo mkdir -p #{config.provisioning_path}")
22
- ssh.exec!("sudo chown #{env.config.ssh.username} #{config.provisioning_path}")
21
+ ssh.sudo!("mkdir -p #{config.provisioning_path}")
22
+ ssh.sudo!("chown #{env.config.ssh.username} #{config.provisioning_path}")
23
23
  end
24
24
  end
25
25
 
@@ -50,7 +50,7 @@ module Vagrant
50
50
  path = Pathname.new(config.client_key_path)
51
51
 
52
52
  vm.ssh.execute do |ssh|
53
- ssh.exec!("sudo mkdir -p #{path.dirname}")
53
+ ssh.sudo!("mkdir -p #{path.dirname}")
54
54
  end
55
55
  end
56
56
 
@@ -70,13 +70,14 @@ module Vagrant
70
70
  end
71
71
 
72
72
  def run_chef_client
73
- command = "sudo -i 'cd #{config.provisioning_path} && chef-client -c client.rb -j dna.json'"
73
+ commands = ["cd #{config.provisioning_path}",
74
+ "chef-client -c client.rb -j dna.json"]
74
75
 
75
76
  env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
76
77
  vm.ssh.execute do |ssh|
77
- ssh.exec!(command) do |channel, type, data|
78
+ ssh.sudo!(commands) do |channel, type, data|
78
79
  if type == :exit_status
79
- ssh.check_exit_status(data, command)
80
+ ssh.check_exit_status(data, commands)
80
81
  else
81
82
  env.ui.info("#{data}: #{type}")
82
83
  end
@@ -60,12 +60,12 @@ module Vagrant
60
60
  end
61
61
 
62
62
  def run_chef_solo
63
- command = "sudo -i 'cd #{config.provisioning_path} && chef-solo -c solo.rb -j dna.json'"
63
+ commands = ["cd #{config.provisioning_path}", "chef-solo -c solo.rb -j dna.json"]
64
64
 
65
65
  env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
66
66
  vm.ssh.execute do |ssh|
67
- ssh.exec!(command) do |channel, type, data|
68
- ssh.check_exit_status(data, command) if type == :exit_status
67
+ ssh.sudo!(commands) do |channel, type, data|
68
+ ssh.check_exit_status(data, commands) if type == :exit_status
69
69
  env.ui.info("#{data}: #{type}") if type != :exit_status
70
70
  end
71
71
  end
@@ -107,7 +107,7 @@ module Vagrant
107
107
 
108
108
  def verify_binary(binary)
109
109
  vm.ssh.execute do |ssh|
110
- ssh.exec!("sudo -i which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
110
+ ssh.sudo!("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
111
111
  end
112
112
  end
113
113
 
@@ -117,14 +117,15 @@ module Vagrant
117
117
  options << config.computed_manifest_file
118
118
  options = options.join(" ")
119
119
 
120
- command = "sudo -i 'cd #{manifests_guest_path}; puppet #{options}'"
120
+ commands = ["cd #{manifests_guest_path}",
121
+ "puppet #{options}"]
121
122
 
122
123
  env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file)
123
124
 
124
125
  vm.ssh.execute do |ssh|
125
- ssh.exec! command do |ch, type, data|
126
+ ssh.sudo! commands do |ch, type, data|
126
127
  if type == :exit_status
127
- ssh.check_exit_status(data, command)
128
+ ssh.check_exit_status(data, commands)
128
129
  else
129
130
  env.ui.info(data)
130
131
  end
@@ -26,9 +26,7 @@ module Vagrant
26
26
 
27
27
  def verify_binary(binary)
28
28
  vm.ssh.execute do |ssh|
29
- ssh.shell do |sh|
30
- sh.execute("sudo -i which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary)
31
- end
29
+ ssh.sudo!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary)
32
30
  end
33
31
  end
34
32
 
@@ -41,13 +39,13 @@ module Vagrant
41
39
  cn = env.config.vm.box
42
40
  end
43
41
 
44
- command = "sudo -i puppetd #{options} --server #{config.puppet_server} --certname #{cn}"
42
+ commands = "puppetd #{options} --server #{config.puppet_server} --certname #{cn}"
45
43
 
46
44
  env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
47
45
 
48
46
  vm.ssh.execute do |ssh|
49
- ssh.exec!(command) do |channel, type, data|
50
- ssh.check_exit_status(data, command) if type == :exit_status
47
+ ssh.sudo!(commands) do |channel, type, data|
48
+ ssh.check_exit_status(data, commands) if type == :exit_status
51
49
  env.ui.info(data) if type != :exit_status
52
50
  end
53
51
  end
@@ -0,0 +1,52 @@
1
+ module Vagrant
2
+ module Provisioners
3
+ class Shell < Base
4
+ register :shell
5
+
6
+ class Config < Vagrant::Config::Base
7
+ attr_accessor :path
8
+ attr_accessor :upload_path
9
+
10
+ def initialize
11
+ @upload_path = "/tmp/vagrant-shell"
12
+ end
13
+
14
+ def expanded_path
15
+ Pathname.new(path).expand_path(env.root_path) if path
16
+ end
17
+
18
+ def validate(errors)
19
+ super
20
+
21
+ if !path
22
+ errors.add(I18n.t("vagrant.provisioners.shell.path_not_set"))
23
+ elsif !expanded_path.file?
24
+ errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path))
25
+ end
26
+
27
+ if !upload_path
28
+ errors.add(I18n.t("vagrant.provisioners.shell.upload_path_not_set"))
29
+ end
30
+ end
31
+ end
32
+
33
+ def provision!
34
+ commands = ["chmod +x #{config.upload_path}", config.upload_path]
35
+
36
+ # Upload the script to the VM
37
+ vm.ssh.upload!(config.expanded_path.to_s, config.upload_path)
38
+
39
+ # Execute it with sudo
40
+ vm.ssh.execute do |ssh|
41
+ ssh.sudo!(commands) do |ch, type, data|
42
+ if type == :exit_status
43
+ ssh.check_exit_status(data, commands)
44
+ else
45
+ env.ui.info(data)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -44,7 +44,12 @@ module Vagrant
44
44
  "-o StrictHostKeyChecking=no", "-o IdentitiesOnly=yes",
45
45
  "-i #{options[:private_key_path]}"]
46
46
  command_options << "-o ForwardAgent=yes" if env.config.ssh.forward_agent
47
- command_options << "-o ForwardX11=yes" if env.config.ssh.forward_x11
47
+
48
+ if env.config.ssh.forward_x11
49
+ # Both are required so that no warnings are shown regarding X11
50
+ command_options << "-o ForwardX11=yes"
51
+ command_options << "-o ForwardX11Trusted=yes"
52
+ end
48
53
 
49
54
  # Some hackery going on here. On Mac OS X Leopard (10.5), exec fails
50
55
  # (GH-51). As a workaround, we fork and wait. On all other platforms,
@@ -70,6 +75,7 @@ module Vagrant
70
75
  Net::SSH.start(env.config.ssh.host,
71
76
  env.config.ssh.username,
72
77
  opts.merge( :keys => [env.config.ssh.private_key_path],
78
+ :keys_only => true,
73
79
  :user_known_hosts_file => [],
74
80
  :paranoid => false,
75
81
  :config => false)) do |ssh|
@@ -22,11 +22,55 @@ module Vagrant
22
22
  false
23
23
  end
24
24
 
25
+ # Executes a given command on the SSH session using `sudo` and
26
+ # blocks until the command completes. This takes the same parameters
27
+ # as {#exec!}. The only difference is that the command can be an
28
+ # array of commands, which will be placed into the same script.
29
+ #
30
+ # This is different than just calling {#exec!} with `sudo`, since
31
+ # this command is tailor-made to be compliant with older versions
32
+ # of `sudo`.
33
+ def sudo!(commands, options=nil, &block)
34
+ session.open_channel do |ch|
35
+ ch.exec("sudo -i sh") do |ch2, success|
36
+ # Output each command as if they were entered on the command line
37
+ [commands].flatten.each do |command|
38
+ ch2.send_data "#{command}\n"
39
+ end
40
+
41
+ # Remember to exit or we'll hang!
42
+ ch2.send_data "exit\n"
43
+
44
+ # Setup the callbacks with our options so we get all the
45
+ # stdout/stderr and error checking goodies
46
+ setup_channel_callbacks(ch2, commands, options, block)
47
+ end
48
+
49
+ ch.wait
50
+ end
51
+ end
52
+
25
53
  # Executes a given command on the SSH session and blocks until
26
54
  # the command completes. This is an almost line for line copy of
27
55
  # the actual `exec!` implementation, except that this
28
56
  # implementation also reports `:exit_status` to the block if given.
29
57
  def exec!(command, options=nil, &block)
58
+ retryable(:tries => 5, :on => IOError, :sleep => 0.5) do
59
+ metach = session.open_channel do |channel|
60
+ channel.exec(command) do |ch, success|
61
+ raise "could not execute command: #{command.inspect}" unless success
62
+ setup_channel_callbacks(ch, command, options, block)
63
+ end
64
+ end
65
+
66
+ metach.wait
67
+ metach[:result]
68
+ end
69
+ end
70
+
71
+ # Sets up the channel callbacks to properly check exit statuses and
72
+ # callback on stdout/stderr.
73
+ def setup_channel_callbacks(channel, command, options, block)
30
74
  options = { :error_check => true }.merge(options || {})
31
75
 
32
76
  block ||= Proc.new do |ch, type, data|
@@ -36,41 +80,30 @@ module Vagrant
36
80
  ch[:result] << data if [:stdout, :stderr].include?(type)
37
81
  end
38
82
 
39
- retryable(:tries => 5, :on => IOError, :sleep => 0.5) do
40
- metach = session.open_channel do |channel|
41
- channel.exec(command) do |ch, success|
42
- raise "could not execute command: #{command.inspect}" unless success
43
-
44
- # Output stdout data to the block
45
- channel.on_data do |ch2, data|
46
- block.call(ch2, :stdout, data)
47
- end
48
-
49
- # Output stderr data to the block
50
- channel.on_extended_data do |ch2, type, data|
51
- block.call(ch2, :stderr, data)
52
- end
83
+ # Output stdout data to the block
84
+ channel.on_data do |ch2, data|
85
+ block.call(ch2, :stdout, data)
86
+ end
53
87
 
54
- # Output exit status information to the block
55
- channel.on_request("exit-status") do |ch2, data|
56
- block.call(ch2, :exit_status, data.read_long)
57
- end
58
- end
59
- end
88
+ # Output stderr data to the block
89
+ channel.on_extended_data do |ch2, type, data|
90
+ block.call(ch2, :stderr, data)
91
+ end
60
92
 
61
- metach.wait
62
- metach[:result]
93
+ # Output exit status information to the block
94
+ channel.on_request("exit-status") do |ch2, data|
95
+ block.call(ch2, :exit_status, data.read_long)
63
96
  end
64
97
  end
65
98
 
66
99
  # Checks for an erroroneous exit status and raises an exception
67
100
  # if so.
68
- def check_exit_status(exit_status, command, options=nil)
101
+ def check_exit_status(exit_status, commands, options=nil)
69
102
  if exit_status != 0
70
103
  options = {
71
104
  :_error_class => Errors::VagrantError,
72
105
  :_key => :ssh_bad_exit_status,
73
- :command => command
106
+ :command => [commands].flatten.join("\n")
74
107
  }.merge(options || {})
75
108
 
76
109
  raise options[:_error_class], options
@@ -1,6 +1,7 @@
1
1
  # These can't be autoloaded because they have to register functionality
2
2
  # with Vagrant core.
3
3
  require 'vagrant/systems/base'
4
+ require 'vagrant/systems/freebsd'
4
5
  require 'vagrant/systems/linux'
5
6
  require 'vagrant/systems/solaris'
6
7
 
@@ -78,6 +78,10 @@ module Vagrant
78
78
  #
79
79
  # @param [Hash] net_options The options for the network.
80
80
  def enable_host_only_network(net_options); end
81
+
82
+ def change_host_name(name)
83
+ raise BaseError, :_key => :unsupported_host_name
84
+ end
81
85
  end
82
86
  end
83
87
  end
@@ -21,6 +21,15 @@ module Vagrant
21
21
  ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
22
22
  end
23
23
  end
24
+
25
+ def change_host_name(name)
26
+ vm.ssh.execute do |ssh|
27
+ if !ssh.test?("sudo hostname | grep '#{name}'")
28
+ ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
29
+ ssh.exec!("sudo service hostname start")
30
+ end
31
+ end
32
+ end
24
33
  end
25
34
  end
26
35
  end
@@ -0,0 +1,84 @@
1
+ module Vagrant
2
+ module Systems
3
+ # A general Vagrant system implementation for "freebsd".
4
+ #
5
+ # Contributed by Kenneth Vestergaard <kvs@binarysolutions.dk>
6
+ class FreeBSD < Base
7
+ # A custom config class which will be made accessible via `config.freebsd`
8
+ # This is not necessary for all system implementers, of course. However,
9
+ # generally, Vagrant tries to make almost every aspect of its execution
10
+ # configurable, and this assists that goal.
11
+ class FreeBSDConfig < Vagrant::Config::Base
12
+ configures :freebsd
13
+
14
+ attr_accessor :halt_timeout
15
+ attr_accessor :halt_check_interval
16
+
17
+ def initialize
18
+ @halt_timeout = 30
19
+ @halt_check_interval = 1
20
+ end
21
+ end
22
+
23
+ # Here for whenever it may be used.
24
+ class FreeBSDError < Errors::VagrantError
25
+ error_namespace("vagrant.systems.freebsd")
26
+ end
27
+
28
+ def halt
29
+ vm.env.ui.info I18n.t("vagrant.systems.freebsd.attempting_halt")
30
+ vm.ssh.execute do |ssh|
31
+ ssh.exec!("sudo shutdown -p now")
32
+ end
33
+
34
+ # Wait until the VM's state is actually powered off. If this doesn't
35
+ # occur within a reasonable amount of time (15 seconds by default),
36
+ # then simply return and allow Vagrant to kill the machine.
37
+ count = 0
38
+ while vm.vm.state != :powered_off
39
+ count += 1
40
+
41
+ return if count >= vm.env.config.freebsd.halt_timeout
42
+ sleep vm.env.config.freebsd.halt_check_interval
43
+ end
44
+ end
45
+
46
+ # TODO: Error/warning about this.
47
+ # def mount_shared_folder(ssh, name, guestpath)
48
+ # ssh.exec!("sudo mkdir -p #{guestpath}")
49
+ # # Using a custom mount method here; could use improvement.
50
+ # ssh.exec!("sudo mount -t vboxfs v-root #{guestpath}")
51
+ # ssh.exec!("sudo chown #{vm.env.config.ssh.username} #{guestpath}")
52
+ # end
53
+
54
+ def mount_nfs(ip, folders)
55
+ folders.each do |name, opts|
56
+ vm.ssh.execute do |ssh|
57
+ ssh.exec!("sudo mkdir -p #{opts[:guestpath]}")
58
+ ssh.exec!("sudo mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}")
59
+ end
60
+ end
61
+ end
62
+
63
+ def prepare_host_only_network(net_options=nil)
64
+ # Remove any previous host only network additions to the
65
+ # interface file.
66
+ vm.ssh.execute do |ssh|
67
+ # Clear out any previous entries
68
+ ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > /tmp/rc.conf")
69
+ ssh.exec!("sudo mv /tmp/rc.conf /etc/rc.conf")
70
+ end
71
+ end
72
+
73
+ def enable_host_only_network(net_options)
74
+ entry = "#VAGRANT-BEGIN\nifconfig_em#{net_options[:adapter]}=\"inet #{net_options[:ip]} netmask #{net_options[:netmask]}\"\n#VAGRANT-END\n"
75
+ vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
76
+
77
+ vm.ssh.execute do |ssh|
78
+ ssh.exec!("sudo su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'")
79
+ ssh.exec!("sudo ifconfig em#{net_options[:adapter]} inet #{net_options[:ip]} netmask #{net_options[:netmask]}")
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -16,7 +16,7 @@ module Vagrant
16
16
  vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
17
17
 
18
18
  vm.ssh.execute do |ssh|
19
- ssh.exec!("sudo ln -s /etc/init.d/net.lo /etc/init.d/net.eth#{net_options[:adapter]}")
19
+ ssh.exec!("sudo ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{net_options[:adapter]}")
20
20
  ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} stop 2> /dev/null")
21
21
  ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/conf.d/net'")
22
22
  ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} start")
@@ -23,9 +23,17 @@ module Vagrant
23
23
  ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
24
24
  end
25
25
  end
26
+
27
+ def change_host_name(name)
28
+ vm.ssh.execute do |ssh|
29
+ # Only do this if the hostname is not already set
30
+ if !ssh.test?("sudo hostname | grep '#{name}'")
31
+ ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
32
+ ssh.exec!("sudo hostname #{name}")
33
+ ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
34
+ end
35
+ end
36
+ end
26
37
  end
27
38
  end
28
39
  end
29
-
30
-
31
-
@@ -2,5 +2,5 @@ module Vagrant
2
2
  # This will always be up to date with the current version of Vagrant,
3
3
  # since it is used to generate the gemspec and is also the source of
4
4
  # the version for `vagrant -v`
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
@@ -58,10 +58,11 @@ module Vagrant
58
58
  elsif system.is_a?(Symbol)
59
59
  # Hard-coded internal systems
60
60
  mapping = {
61
- :debian => Systems::Debian,
62
- :gentoo => Systems::Gentoo,
63
- :redhat => Systems::Redhat,
64
- :linux => Systems::Linux,
61
+ :debian => Systems::Debian,
62
+ :freebsd => Systems::FreeBSD,
63
+ :gentoo => Systems::Gentoo,
64
+ :redhat => Systems::Redhat,
65
+ :linux => Systems::Linux,
65
66
  :solaris => Systems::Solaris
66
67
  }
67
68
 
@@ -102,7 +102,7 @@ en:
102
102
 
103
103
  For a more detailed guide please consult:
104
104
 
105
- http://vagrantup.com/docs/getting-started/windows
105
+ http://vagrantup.com/docs/getting-started/setup/windows.html
106
106
 
107
107
  system:
108
108
  invalid_class: |-
@@ -133,10 +133,10 @@ en:
133
133
  virtualbox_not_detected: |-
134
134
  Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
135
135
  If VirtualBox is installed, it may be an incorrect version. Vagrant currently
136
- requires VirtualBox 3.2.x. Please install the proper version to continue.
136
+ requires VirtualBox 4.0.x. Please install the proper version to continue.
137
137
  virtualbox_not_detected_win64: |-
138
138
  Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed
139
- with version 3.2.0 or higher.
139
+ with version 4.0.0 or higher.
140
140
 
141
141
  Additionally, it appears you're on 64-bit Windows. If this is the case, and
142
142
  VirtualBox is properly installed with the correct version, then please make
@@ -320,6 +320,8 @@ en:
320
320
  Skipping port forwarding '%{name}'.
321
321
  halt:
322
322
  force: Forcing shutdown of VM...
323
+ host_name:
324
+ setting: "Setting host name..."
323
325
  import:
324
326
  importing: Importing base box '%{name}'...
325
327
  failure: |-
@@ -489,6 +491,11 @@ en:
489
491
  Puppet properly installed.
490
492
  running_puppetd: "Running Puppet agent..."
491
493
 
494
+ shell:
495
+ path_not_set: "`path` parameter pointing to script file to execute for shell provisioner is required"
496
+ path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}"
497
+ upload_path_not_set: "`upload_path` must be set for the shell provisioner."
498
+
492
499
  systems:
493
500
  base:
494
501
  unsupported_host_only: |-
@@ -499,7 +506,10 @@ en:
499
506
  Most of the time this is simply due to the fact that no one has contributed
500
507
  back the SSH commands necessary to set this up. Please report a bug and this
501
508
  will be fixed for your distro.
502
-
509
+ unsupported_host_name: |-
510
+ Setting host name is currently only supported on Debian, Ubuntu and RedHat.
511
+ If you'd like your guest OS to be supported, please open a ticket on the
512
+ project.
503
513
  linux:
504
514
  attempting_halt: "Attempting graceful shutdown of linux..."
505
515
  mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
@@ -512,3 +522,6 @@ en:
512
522
 
513
523
  solaris:
514
524
  attempting_halt: "Attempting graceful shutdown of solaris..."
525
+
526
+ freebsd:
527
+ attempting_halt: "Attempting graceful shutdown of FreeBSD..."
@@ -1,5 +1,5 @@
1
1
  Host <%= host_key %>
2
- HostName 127.0.0.1
2
+ HostName <%= ssh_host %>
3
3
  User <%= ssh_user %>
4
4
  Port <%= ssh_port %>
5
5
  UserKnownHostsFile /dev/null
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class HostNameVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::HostName
6
+ @app, @env = action_env
7
+ @instance = @klass.new(@app, @env)
8
+
9
+ @vm = mock("vm")
10
+ @env["vm"] = @vm
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+ end
15
+
16
+ should "not run anything if no host name is set" do
17
+ @env["config"].vm.host_name = nil
18
+ @env["vm"].expects(:system).never
19
+ @app.expects(:call).with(@env).once
20
+
21
+ @instance.call(@env)
22
+ end
23
+
24
+ should "change host name if set" do
25
+ @env["config"].vm.host_name = "foo"
26
+
27
+ system = mock("system")
28
+ @vm.stubs(:system).returns(system)
29
+
30
+ seq = sequence("host_seq")
31
+ @app.expects(:call).with(@env).in_sequence(seq)
32
+ system.expects(:change_host_name).with(@env["config"].vm.host_name).in_sequence(seq)
33
+
34
+ @instance.call(@env)
35
+ end
36
+ end
@@ -117,7 +117,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
117
117
 
118
118
  should "create the folder using the dirname of the path" do
119
119
  ssh = mock("ssh")
120
- ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
120
+ ssh.expects(:sudo!).with("mkdir -p #{@path.dirname}").once
121
121
  @vm.ssh.expects(:execute).yields(ssh)
122
122
  @action.create_client_key_folder
123
123
  end
@@ -173,12 +173,12 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
173
173
  end
174
174
 
175
175
  should "cd into the provisioning directory and run chef client" do
176
- @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-client -c client.rb -j dna.json'").once
176
+ @ssh.expects(:sudo!).with(["cd #{@config.provisioning_path}", "chef-client -c client.rb -j dna.json"]).once
177
177
  @action.run_chef_client
178
178
  end
179
179
 
180
180
  should "check the exit status if that is given" do
181
- @ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
181
+ @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo)
182
182
  @ssh.expects(:check_exit_status).with(:foo, anything).once
183
183
  @action.run_chef_client
184
184
  end
@@ -206,12 +206,12 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
206
206
  end
207
207
 
208
208
  should "cd into the provisioning directory and run chef solo" do
209
- @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-solo -c solo.rb -j dna.json'").once
209
+ @ssh.expects(:sudo!).with(["cd #{@config.provisioning_path}", "chef-solo -c solo.rb -j dna.json"]).once
210
210
  @action.run_chef_solo
211
211
  end
212
212
 
213
213
  should "check the exit status if that is given" do
214
- @ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
214
+ @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo)
215
215
  @ssh.expects(:check_exit_status).with(:foo, anything).once
216
216
  @action.run_chef_solo
217
217
  end
@@ -73,7 +73,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
73
73
 
74
74
  should "verify binary exists" do
75
75
  binary = "foo"
76
- @ssh.expects(:exec!).with("sudo -i which #{binary}", anything)
76
+ @ssh.expects(:sudo!).with("which #{binary}", anything)
77
77
  @action.verify_binary(binary)
78
78
  end
79
79
  end
@@ -82,8 +82,8 @@ class ChefProvisionerTest < Test::Unit::TestCase
82
82
  should "create and chown the folder to the ssh user" do
83
83
  ssh_seq = sequence("ssh_seq")
84
84
  ssh = mock("ssh")
85
- ssh.expects(:exec!).with("sudo mkdir -p #{@config.provisioning_path}").once.in_sequence(ssh_seq)
86
- ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@config.provisioning_path}").once.in_sequence(ssh_seq)
85
+ ssh.expects(:sudo!).with("mkdir -p #{@config.provisioning_path}").once.in_sequence(ssh_seq)
86
+ ssh.expects(:sudo!).with("chown #{@env.config.ssh.username} #{@config.provisioning_path}").once.in_sequence(ssh_seq)
87
87
  @vm.ssh.expects(:execute).yields(ssh)
88
88
  @action.chown_provisioning_folder
89
89
  end
@@ -25,13 +25,12 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase
25
25
  setup do
26
26
  @ssh = mock("ssh")
27
27
  @shell = mock("shell")
28
- @ssh.stubs(:shell).yields(@shell)
29
28
  @vm.ssh.stubs(:execute).yields(@ssh)
30
29
  end
31
30
 
32
31
  should "verify binary exists" do
33
32
  binary = "foo"
34
- @shell.expects(:execute).with("sudo -i which #{binary}", anything)
33
+ @ssh.expects(:sudo!).with("which #{binary}", anything)
35
34
  @action.verify_binary(binary)
36
35
  end
37
36
  end
@@ -44,24 +43,24 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase
44
43
  end
45
44
 
46
45
  should "run the puppetd client" do
47
- @ssh.expects(:exec!).with("sudo -i puppetd --server #{@config.puppet_server} --certname #{@cn}").once
46
+ @ssh.expects(:sudo!).with("puppetd --server #{@config.puppet_server} --certname #{@cn}").once
48
47
  @action.run_puppetd_client
49
48
  end
50
49
 
51
50
  should "run puppetd with given options when given as an array" do
52
51
  @config.options = ["--modulepath", "modules", "--verbose"]
53
- @ssh.expects(:exec!).with("sudo -i puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
52
+ @ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
54
53
  @action.run_puppetd_client
55
54
  end
56
55
 
57
56
  should "run puppetd with the options when given as a string" do
58
57
  @config.options = "--modulepath modules --verbose"
59
- @ssh.expects(:exec!).with("sudo -i puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
58
+ @ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
60
59
  @action.run_puppetd_client
61
60
  end
62
61
 
63
62
  should "check the exit status if that is given" do
64
- @ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
63
+ @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo)
65
64
  @ssh.expects(:check_exit_status).with(:foo, anything).once
66
65
  @action.run_puppetd_client
67
66
  end
@@ -138,7 +138,7 @@ class PuppetProvisionerTest < Test::Unit::TestCase
138
138
 
139
139
  should "verify binary exists" do
140
140
  binary = "foo"
141
- @ssh.expects(:exec!).with("sudo -i which #{binary}", anything)
141
+ @ssh.expects(:sudo!).with("which #{binary}", anything)
142
142
  @action.verify_binary(binary)
143
143
  end
144
144
  end
@@ -151,7 +151,7 @@ class PuppetProvisionerTest < Test::Unit::TestCase
151
151
  end
152
152
 
153
153
  def expect_puppet_command(command)
154
- @ssh.expects(:exec!).with("sudo -i 'cd #{@action.manifests_guest_path}; #{command}'")
154
+ @ssh.expects(:sudo!).with(["cd #{@action.manifests_guest_path}", command])
155
155
  end
156
156
 
157
157
  should "cd into the pp_path directory and run puppet" do
@@ -0,0 +1,68 @@
1
+ require "test_helper"
2
+
3
+ class ShellProvisionerTest < Test::Unit::TestCase
4
+ setup do
5
+ clean_paths
6
+
7
+ @klass = Vagrant::Provisioners::Shell
8
+ @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
9
+ @config = @klass::Config.new
10
+ @config.top = Vagrant::Config::Top.new(@action_env.env)
11
+ @action = @klass.new(@action_env, @config)
12
+
13
+ @config.path = "foo"
14
+ end
15
+
16
+ context "config" do
17
+ setup do
18
+ @errors = Vagrant::Config::ErrorRecorder.new
19
+
20
+ # Start in a valid state (verified by a test below)
21
+ @config.path = "foo"
22
+ File.open(@config.expanded_path, "w") { |f| f.puts "HELLO" }
23
+ end
24
+
25
+ should "be valid" do
26
+ @config.validate(@errors)
27
+ assert @errors.errors.empty?
28
+ end
29
+
30
+ should "be invalid if the path is not set" do
31
+ @config.path = nil
32
+
33
+ @config.validate(@errors)
34
+ assert !@errors.errors.empty?
35
+ end
36
+
37
+ should "be invalid if the path does not exist" do
38
+ @config.path = "bar"
39
+
40
+ @config.validate(@errors)
41
+ assert !@errors.errors.empty?
42
+ end
43
+
44
+ should "be invalid if the upload path is not set" do
45
+ @config.upload_path = nil
46
+
47
+ @config.validate(@errors)
48
+ assert !@errors.errors.empty?
49
+ end
50
+ end
51
+
52
+ context "provisioning" do
53
+ setup do
54
+ @ssh = mock("ssh")
55
+ @action.vm.ssh.stubs(:execute).yields(@ssh)
56
+ end
57
+
58
+ should "upload the file, chmod, then execute it" do
59
+ commands = ["chmod +x #{@config.upload_path}", @config.upload_path]
60
+
61
+ p_seq = sequence("provisioning")
62
+ @action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq)
63
+ @ssh.expects(:sudo!).with(commands).in_sequence(p_seq)
64
+
65
+ @action.provision!
66
+ end
67
+ end
68
+ end
@@ -147,6 +147,7 @@ class SshTest < Test::Unit::TestCase
147
147
  assert_equal @env.config.ssh.username, username
148
148
  assert_equal @ssh.port, opts[:port]
149
149
  assert_equal [@env.config.ssh.private_key_path], opts[:keys]
150
+ assert opts[:keys_only]
150
151
  true
151
152
  end
152
153
  @ssh.execute
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency "erubis", "~> 2.6.6"
19
19
  s.add_dependency "json", "~> 1.4.6"
20
20
  s.add_dependency "mario", "~> 0.0.6"
21
- s.add_dependency "net-ssh", "~> 2.0.23"
21
+ s.add_dependency "net-ssh", "~> 2.1.0"
22
22
  s.add_dependency "net-scp", "~> 1.0.4"
23
23
  s.add_dependency "i18n", "~> 0.5.0"
24
24
  s.add_dependency "thor", "~> 0.14.6"
25
- s.add_dependency "virtualbox", "~> 0.8.2"
25
+ s.add_dependency "virtualbox", "~> 0.8.3"
26
26
 
27
27
  s.add_development_dependency "rake"
28
28
  s.add_development_dependency "contest", ">= 0.1.2"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 0
9
- version: 0.7.0
8
+ - 1
9
+ version: 0.7.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mitchell Hashimoto
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-19 00:00:00 -08:00
18
+ date: 2011-01-28 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -87,9 +87,9 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  segments:
89
89
  - 2
90
+ - 1
90
91
  - 0
91
- - 23
92
- version: 2.0.23
92
+ version: 2.1.0
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: *id005
@@ -148,8 +148,8 @@ dependencies:
148
148
  segments:
149
149
  - 0
150
150
  - 8
151
- - 2
152
- version: 0.8.2
151
+ - 3
152
+ version: 0.8.3
153
153
  type: :runtime
154
154
  prerelease: false
155
155
  version_requirements: *id009
@@ -266,6 +266,7 @@ files:
266
266
  - lib/vagrant/action/vm/forward_ports.rb
267
267
  - lib/vagrant/action/vm/forward_ports_helpers.rb
268
268
  - lib/vagrant/action/vm/halt.rb
269
+ - lib/vagrant/action/vm/host_name.rb
269
270
  - lib/vagrant/action/vm/import.rb
270
271
  - lib/vagrant/action/vm/match_mac_address.rb
271
272
  - lib/vagrant/action/vm/network.rb
@@ -331,11 +332,13 @@ files:
331
332
  - lib/vagrant/provisioners/chef_solo.rb
332
333
  - lib/vagrant/provisioners/puppet.rb
333
334
  - lib/vagrant/provisioners/puppet_server.rb
335
+ - lib/vagrant/provisioners/shell.rb
334
336
  - lib/vagrant/ssh.rb
335
337
  - lib/vagrant/ssh/session.rb
336
338
  - lib/vagrant/systems.rb
337
339
  - lib/vagrant/systems/base.rb
338
340
  - lib/vagrant/systems/debian.rb
341
+ - lib/vagrant/systems/freebsd.rb
339
342
  - lib/vagrant/systems/gentoo.rb
340
343
  - lib/vagrant/systems/linux.rb
341
344
  - lib/vagrant/systems/linux/config.rb
@@ -394,6 +397,7 @@ files:
394
397
  - test/vagrant/action/vm/forward_ports_helpers_test.rb
395
398
  - test/vagrant/action/vm/forward_ports_test.rb
396
399
  - test/vagrant/action/vm/halt_test.rb
400
+ - test/vagrant/action/vm/host_name_test.rb
397
401
  - test/vagrant/action/vm/import_test.rb
398
402
  - test/vagrant/action/vm/match_mac_address_test.rb
399
403
  - test/vagrant/action/vm/network_test.rb
@@ -437,6 +441,7 @@ files:
437
441
  - test/vagrant/provisioners/chef_test.rb
438
442
  - test/vagrant/provisioners/puppet_server_test.rb
439
443
  - test/vagrant/provisioners/puppet_test.rb
444
+ - test/vagrant/provisioners/shell_test.rb
440
445
  - test/vagrant/ssh/session_test.rb
441
446
  - test/vagrant/ssh_test.rb
442
447
  - test/vagrant/systems/base_test.rb
@@ -466,7 +471,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
466
471
  requirements:
467
472
  - - ">="
468
473
  - !ruby/object:Gem::Version
469
- hash: -3286949326636393746
474
+ hash: 1780875607345345301
470
475
  segments:
471
476
  - 0
472
477
  version: "0"