Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Only sudo -E when using --forward-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
xtoddx committed Aug 11, 2014
1 parent f87a236 commit 397a80f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/knife-solo/ssh_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,24 @@ def ssh_args
[host_arg, config_arg, ident_arg, forward_arg, port_arg, knownhosts_arg, stricthosts_arg].compact.join(' ')
end

def custom_sudo_command
if sudo_command=config[:sudo_command]
Chef::Log.debug("Using replacement sudo command: #{sudo_command}")
return sudo_command
end
end

def standard_sudo_command
return unless sudo_available?
if config[:forward_agent]
return 'sudo -E -p \'knife sudo password: \''
else
return 'sudo -p \'knife sudo password: \''
end
end

def sudo_command
config[:sudo_command]
custom_sudo_command || standard_sudo_command || ''
end

def startup_script
Expand All @@ -208,15 +224,7 @@ def sudo_available?
end

def process_sudo(command)
if sudo_command
Chef::Log.debug("Using replacement sudo command: #{sudo_command}")
replacement = sudo_command
elsif sudo_available?
replacement = 'sudo -E -p \'knife sudo password: \''
else
replacement = ''
end
command.gsub(/sudo/, replacement)
command.gsub(/sudo/, sudo_command)
end

def process_startup_file(command)
Expand Down

0 comments on commit 397a80f

Please sign in to comment.