Class: VagrantPlugins::SimpleCloud::Actions::SetupSudo
- Inherits:
-
Object
- Object
- VagrantPlugins::SimpleCloud::Actions::SetupSudo
- Defined in:
- lib/vagrant-simplecloud/actions/setup_sudo.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ SetupSudo
constructor
A new instance of SetupSudo.
Constructor Details
#initialize(app, env) ⇒ SetupSudo
Returns a new instance of SetupSudo.
5 6 7 8 9 |
# File 'lib/vagrant-simplecloud/actions/setup_sudo.rb', line 5 def initialize(app, env) @app = app @machine = env[:machine] @logger = Log4r::Logger.new('vagrant::simplecloud::setup_sudo') end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant-simplecloud/actions/setup_sudo.rb', line 11 def call(env) # check if setup is enabled return @app.call(env) unless @machine.provider_config.setup? # override ssh username to root user = @machine.config.ssh.username @machine.config.ssh.username = 'root' # check for guest name available in Vagrant 1.2 first guest_name = @machine.guest.name if @machine.guest.respond_to?(:name) guest_name ||= @machine.guest.to_s.downcase case guest_name when /redhat/ @machine.communicate.execute('yum install sudo') env[:ui].info I18n.t('vagrant_simple_cloud.info.modifying_sudo') # disable tty requirement for sudo @machine.communicate.execute(<<-'BASH') sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers BASH when /debian/ @machine.communicate.execute('apt-get install sudo') env[:ui].info I18n.t('vagrant_simple_cloud.info.modifying_sudo') # disable tty requirement for sudo @machine.communicate.execute(<<-'BASH') sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers BASH end # reset ssh username @machine.config.ssh.username = user @app.call(env) end |