diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2016-01-27 14:09:14 -0500 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2016-01-27 14:13:01 -0500 |
commit | 6bf2f45ff52d252dbada6a1860416fa603be56bd (patch) | |
tree | a9f886209e8d13bb349f6170ca709500ebbad66f | |
parent | 4fa6902c960df565d2475e78d080d620ee0bfd7f (diff) | |
download | ansible-6bf2f45ff52d252dbada6a1860416fa603be56bd.tar.gz |
fix for so su works in more cases
should not fail anymore on csh, fish nor the BSDs
fixes #14116
-rw-r--r-- | lib/ansible/playbook/play_context.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 409f9661b8..1804a032c6 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -451,8 +451,10 @@ class PlayContext(Base): 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() @@ -468,12 +470,14 @@ class PlayContext(Base): 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': |