diff --git a/Vagrantfile b/Vagrantfile index 5edc089..411776e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -17,10 +17,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| rs.admin_password = ENV['VAGRANT_ADMIN_PASSWORD'] rs.api_key = ENV['RAX_API_KEY'] rs.flavor = /1 GB Performance/ - rs.image = /Ubuntu/ + rs.image = "CentOS 6.4" rs.rackspace_region = :iad # rs.rsync_include 'PATTERN' # per man page for rsync + rs.use_tty_workaround = true end # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. diff --git a/lib/vagrant-rackspace/action.rb b/lib/vagrant-rackspace/action.rb index 04f71da..84adbbe 100644 --- a/lib/vagrant-rackspace/action.rb +++ b/lib/vagrant-rackspace/action.rb @@ -43,11 +43,15 @@ def self.action_provision end b2.use Provision + + b2.use TTYWorkaround if env[:machine].provider_config.use_tty_workaround == true + if defined?(SyncedFolders) b2.use SyncedFolders else b2.use SyncFolders end + end end end @@ -113,6 +117,8 @@ def self.action_up b2.use ConnectRackspace b2.use Provision + + b2.use TTYWorkaround if env[:machine].provider_config.use_tty_workaround == true if defined?(SyncedFolders) b2.use SyncedFolders else @@ -181,6 +187,7 @@ def self.action_list_keypairs autoload :ListKeyPairs, action_root.join("list_keypairs") autoload :ListNetworks, action_root.join("list_networks") autoload :ListServers, action_root.join("list_servers") + autoload :TTYWorkaround, action_root.join("tty_workaround") end end end diff --git a/lib/vagrant-rackspace/action/tty_workaround.rb b/lib/vagrant-rackspace/action/tty_workaround.rb new file mode 100644 index 0000000..56816b9 --- /dev/null +++ b/lib/vagrant-rackspace/action/tty_workaround.rb @@ -0,0 +1,25 @@ +require 'log4r' +require 'rbconfig' +require 'vagrant/util/subprocess' + +module VagrantPlugins + module Rackspace + module Action + # This middleware fixes the sudoers file so it allows sudo without a tty. + class TTYWorkaround + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant_rackspace::action::requiretty_workaround_start") + @host_os = RbConfig::CONFIG['host_os'] + end + + def call(env) + @app.call(env) + env[:ui].info(I18n.t("vagrant_rackspace.requiretty_workaround_start")) + env[:machine].communicate.sudo 'sed -i\'.bk\' -e \'s/^\(Defaults\s\+requiretty\)/# \1/\' /etc/sudoers' + env[:ui].info(I18n.t("vagrant_rackspace.requiretty_workaround_end")) + end + end + end + end +end diff --git a/lib/vagrant-rackspace/config.rb b/lib/vagrant-rackspace/config.rb index e1aa526..19fa2b2 100644 --- a/lib/vagrant-rackspace/config.rb +++ b/lib/vagrant-rackspace/config.rb @@ -107,6 +107,7 @@ class Config < Vagrant.plugin("2", :config) # @return [Array] attr_accessor :networks + # Opt files/directories in to the rsync operation performed by this provider # # @return [Array] @@ -119,6 +120,11 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :admin_password + # Whether to apply a workaround to disable the requiretty sudoer option. + # + # @return [Boolean] + attr_accessor :use_tty_workaround + # Default Rackspace Cloud Network IDs SERVICE_NET_ID = '11111111-1111-1111-1111-111111111111' PUBLIC_NET_ID = '00000000-0000-0000-0000-000000000000' @@ -139,6 +145,7 @@ def initialize @disk_config = UNSET_VALUE @networks = [] @rsync_includes = [] + @use_tty_workaround = UNSET_VALUE end def finalize! @@ -157,6 +164,7 @@ def finalize! @disk_config = nil if @disk_config == UNSET_VALUE @networks = nil if @networks.empty? @rsync_includes = nil if @rsync_includes.empty? + @use_tty_workaround = nil if @requiretty == UNSET_VALUE if @public_key_path == UNSET_VALUE @public_key_path = Vagrant.source_root.join("keys/vagrant.pub") diff --git a/lib/vagrant-rackspace/plugin.rb b/lib/vagrant-rackspace/plugin.rb index e40b6b3..383b5ed 100644 --- a/lib/vagrant-rackspace/plugin.rb +++ b/lib/vagrant-rackspace/plugin.rb @@ -18,6 +18,11 @@ class Plugin < Vagrant.plugin("2") This plugin enables Vagrant to manage machines in RackSpace Cloud. DESC + action_hook(:tty_workaround, Plugin::ALL_ACTIONS) do |hook| + require_relative 'action/tty_workaround' + hook.after(Vagrant::Action::Builtin::SyncedFolders, Action::TTYWorkaround) + end + config(:rackspace, :provider) do require_relative "config" Config diff --git a/locales/en.yml b/locales/en.yml index bbf114f..06dc49e 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -40,7 +40,11 @@ en: The server will not be deleted. sync_folders: |- Rackspace support for Vagrant 1.3 has been deprecated. Please - upgrade to the latest version of vagrant for continued support. + upgrade to the latest version of vagrant for continued support. + requiretty_workaround_start: |- + Applying requiretty workaround... + requiretty_workaround_end: |- + requiretty workaround complete! config: api_key_required: |- diff --git a/spec/vagrant-rackspace/config_spec.rb b/spec/vagrant-rackspace/config_spec.rb index a5f3239..0f9cf43 100644 --- a/spec/vagrant-rackspace/config_spec.rb +++ b/spec/vagrant-rackspace/config_spec.rb @@ -39,7 +39,8 @@ :server_name, :disk_config, :username, - :admin_password].each do |attribute| + :admin_password, + :use_tty_workaround].each do |attribute| it "should not default #{attribute} if overridden" do subject.send("#{attribute}=".to_sym, "foo") subject.finalize! @@ -56,7 +57,7 @@ subject.send(:networks).should include(VagrantPlugins::Rackspace::Config::SERVICE_NET_ID) end - it "should not default rsync_includes if overridden" do + it "should not default rsync_includes if overridden" do inc = "core" subject.send(:rsync_include, inc) subject.finalize!