mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix for so su works in more cases
should not fail anymore on csh, fish nor the BSDs fixes #14116
This commit is contained in:
parent
4fa6902c96
commit
6bf2f45ff5
1 changed files with 7 additions and 3 deletions
|
@ -451,8 +451,10 @@ class PlayContext(Base):
|
||||||
|
|
||||||
if self.become_method == 'sudo':
|
if self.become_method == 'sudo':
|
||||||
# If we have a password, we run sudo with a randomly-generated
|
# 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.
|
# 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)
|
# Passing a quoted compound command to sudo (or sudo -s)
|
||||||
# directly doesn't work, so we shellquote it with pipes.quote()
|
# directly doesn't work, so we shellquote it with pipes.quote()
|
||||||
|
@ -468,12 +470,14 @@ class PlayContext(Base):
|
||||||
|
|
||||||
elif self.become_method == 'su':
|
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):
|
def detect_su_prompt(data):
|
||||||
SU_PROMPT_LOCALIZATIONS_RE = re.compile("|".join(['(\w+\'s )?' + x + ' ?: ?' for x in SU_PROMPT_LOCALIZATIONS]), flags=re.IGNORECASE)
|
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))
|
return bool(SU_PROMPT_LOCALIZATIONS_RE.match(data))
|
||||||
|
|
||||||
prompt = detect_su_prompt
|
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':
|
elif self.become_method == 'pbrun':
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue