Class: VagrantPlugins::Rimu::Actions::SetupSudo
- Inherits:
-
AbstractAction
- Object
- AbstractAction
- VagrantPlugins::Rimu::Actions::SetupSudo
- Defined in:
- lib/vagrant-rimu/actions/setup_sudo.rb
Instance Method Summary collapse
- #execute(env) ⇒ Object
-
#initialize(app, env) ⇒ SetupSudo
constructor
A new instance of SetupSudo.
- #modify_sudo(env) ⇒ Object
Methods inherited from AbstractAction
Constructor Details
#initialize(app, env) ⇒ SetupSudo
Returns a new instance of SetupSudo.
9 10 11 12 13 |
# File 'lib/vagrant-rimu/actions/setup_sudo.rb', line 9 def initialize(app, env) @app = app @machine = env[:machine] @logger = Log4r::Logger.new('vagrant::rimu::setup_sudo') end |
Instance Method Details
#execute(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vagrant-rimu/actions/setup_sudo.rb', line 15 def execute(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' # modify the sudoers file modify_sudo(env) # reset ssh username @machine.config.ssh.username = user @app.call(env) end |
#modify_sudo(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant-rimu/actions/setup_sudo.rb', line 32 def modify_sudo(env) # 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/ env[:ui].info I18n.t('vagrant_rimu.modifying_sudo') # disable tty requirement for sudo @machine.communicate.execute(<<-'BASH') sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers BASH end end |