Skip to content

Commit

Permalink
fix for so su works in more cases
Browse files Browse the repository at this point in the history
should not fail anymore on csh, fish nor the BSDs
fixes #14116
  • Loading branch information
bcoca committed Jan 27, 2016
1 parent 4fa6902 commit 6bf2f45
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/ansible/playbook/play_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ def make_become_cmd(self, cmd, executable=None):

if self.become_method == 'sudo':
# If we have a password, we run sudo with a randomly-generated
# prompt set using -p. Otherwise we run it with -n, which makes
# prompt set using -p. Otherwise we run it with default -n, which makes
# it fail if it would have prompted for a password.
# Cannot rely on -n as it can be removed from defaults, which should be
# done for older versions of sudo that do not support the option.
#
# Passing a quoted compound command to sudo (or sudo -s)
# directly doesn't work, so we shellquote it with pipes.quote()
Expand All @@ -468,12 +470,14 @@ def make_become_cmd(self, cmd, executable=None):

elif self.become_method == 'su':

# passing code ref to examine prompt as simple string comparisson isn't good enough with su
def detect_su_prompt(data):
SU_PROMPT_LOCALIZATIONS_RE = re.compile("|".join(['(\w+\'s )?' + x + ' ?: ?' for x in SU_PROMPT_LOCALIZATIONS]), flags=re.IGNORECASE)
return bool(SU_PROMPT_LOCALIZATIONS_RE.match(data))

prompt = detect_su_prompt
becomecmd = '%s %s %s -c "%s -c %s"' % (exe, flags, self.become_user, executable, success_cmd)

su_success_cmd = '%s -c %s' % (executable, success_cmd) # this is here cause su too succeptible to overquoting
becomecmd = '%s %s %s -c %s' % (exe, flags, self.become_user, su_success_cmd) #works with sh

elif self.become_method == 'pbrun':

Expand Down

0 comments on commit 6bf2f45

Please sign in to comment.