mitchellh / vagrant-rackspace

Use Vagrant to manage Rackspace Cloud instances.
MIT License
236 stars 155 forks source link

Support for pre-configuring communicator transports (SSH or WinRM) via init_script setting #124

Closed maxlinc closed 9 years ago

maxlinc commented 9 years ago

This adds support for an init_script setting. The init_script is a small script that run before the Vagrant communicator connects to run Vagrant provisioners. The use of init_script should be avoided whenever possible, since a normal provisioner is more portable and easier to troubleshoot when something goes wrong (since Vagrant will capture the results), but the use of an init_script is sometimes needed to configure the communication protocols for communication with Vagrant.

Two known cases that require an init_script (in order to work with Rackspace base images rather than having to create custom images):

The intention of init_script is the same for SSH & WinRM - it after the server is booted but before we tell Vagrant the machine is ready to provision. However, the implementation is slightly different for the two:

It might be possible to run the init_script for SSH via cloud-init, so it would be more consistent with how init_script works for Windows, but that's more complicated, harder to troubleshoot, and I'm not sure cloud-init is supported on all images. So I'm not sure its worth it until there's a known use-case.

maxlinc commented 9 years ago

This is basically an alternate solution for https://github.com/mitchellh/vagrant-rackspace/pull/120, which adds a way to deal with the requiretty issue (https://github.com/mitchellh/vagrant-rackspace/issues/115) while also adding support for Windows.

This is also a lower level solution - which is good because the scripts can be customized (e.g. my WinRM solution uses self-signed certificates; some organizations might want to install a custom CA instead), but we might want higher-level options or auto-detection to decide if a commonly used init_script is needed, like the use_tty_workaround setting from #120.

I think a good option would be to use strings as a script, but to look up symbols from a collection of common scripts that are shipped with the gem. So you could use settings like: init_script = :require_tty_workaround or init_script = :enable_winrm.

@smashwilson @mdarby: Can you review and also let me know about the comment above?

smashwilson commented 9 years ago

@maxlinc Looks reasonable to me, modulo that comment typo.

smashwilson commented 9 years ago

Works for me. :metal: