Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Requiretty workaround #120

Closed
wants to merge 14 commits into from
3 changes: 2 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-rackspace/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions lib/vagrant-rackspace/action/tty_workaround.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/vagrant-rackspace/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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'
Expand All @@ -139,6 +145,7 @@ def initialize
@disk_config = UNSET_VALUE
@networks = []
@rsync_includes = []
@use_tty_workaround = UNSET_VALUE
end

def finalize!
Expand All @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-rackspace/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
5 changes: 3 additions & 2 deletions spec/vagrant-rackspace/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!
Expand Down