Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename should force reboot #179

Closed
moserke opened this issue Mar 26, 2014 · 3 comments
Closed

Rename should force reboot #179

moserke opened this issue Mar 26, 2014 · 3 comments

Comments

@moserke
Copy link

moserke commented Mar 26, 2014

Renaming the host should force a reboot to make the rename take effect. This is extra important if you are domain joining your vagrant box.

We solved this in vagrant-windows 0.1.2 by doing the following in our vagrant files to monkey patch things:

  module Vagrant::Guest
    class Windows < Base
      def change_host_name(name)
        vm.channel.execute("wmic computersystem where name=\"%COMPUTERNAME%\" call rename name=\"#{name}\"", :shell => :cmd)
        # Force a shutdown if the name is not right, default shell is powershell
        vm.channel.execute(<<-EOS
if ((hostname) -ne "#{name}") {
shutdown /s /t 0 /f;
Write-Host "Reboot required, shutting down, 'vagrant up' to restart! (Can take a moment, be patient!)"
exit 1
}
EOS
)
      end
    end
  end

However things seem to be late loaded in the new plugin world and can't seem to find a hook in the Vagrantfile when the VagrantWindows::Guest::Cap::ChangeHostName class is loaded so that it can be Monkey patched with the above second execute.

Is there a good place to do this in the Vagrantfile or a way to set this behavior on the plugin directly?

@moserke
Copy link
Author

moserke commented Mar 26, 2014

Shell provisioner didn't work for us on the 0.1.2 vagrant-windows hence the monkey patch. However, for the new version shell seems to be working again, so solved this by adding a new shell provisioner before chef like such:

    config.vm.provision :shell do |shell|
      shell.inline = <<-EOS
if ((hostname) -ne "#{config.vm.host_name}") {
shutdown /s /t 0 /f;
Write-Host "Reboot required, shutting down, 'vagrant up' to restart! (Can take a moment, be patient!)"
exit 1
}
EOS
    end

@moserke moserke closed this as completed Mar 26, 2014
@sneal
Copy link
Member

sneal commented Mar 26, 2014

I think you're solution with the shell provisioner probably makes the most sense, at least for now. It would be nice if the plugin handled the renaming all the way through with a reboot, but I'm hesitant to force it where the user has no control over it.

@moserke
Copy link
Author

moserke commented Mar 26, 2014

Yeah, I should have tried that first. vagrant-windows 0.1.2 shell provisioner didn't work with windows 2012 so had to go down the monkey patch path. Had forgotten to try the shell provisioner again.

For most folks (not domain joining) just renaming the box and not rebooting probably works just fine. Managing the rename through a whole reboot sounds like the best approach, but don't know if that's possible with how vagrant would deal with things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants