diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 9320a23ed9b..1cb8fa043c4 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -481,7 +481,7 @@ class PlayContext(Base): if self.become_user: flags += ' -u %s ' % self.become_user - becomecmd = '%s %s echo %s && %s %s env ANSIBLE=true %s' % (exe, flags, success_key, exe, flags, cmd) + becomecmd = '%s %s %s -c %s' % (exe, flags, executable, success_cmd) else: raise AnsibleError("Privilege escalation method not found: %s" % self.become_method) diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py index 5434ef30004..844fe87a6bd 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -161,7 +161,7 @@ class TestPlayContext(unittest.TestCase): play_context.become_method = 'doas' cmd = play_context.make_become_cmd(cmd=default_cmd, executable="/bin/bash") - self.assertEqual(cmd, """%s -c '%s %s echo %s && %s %s env ANSIBLE=true %s'""" % (default_exe, doas_exe, doas_flags, play_context.success_key, doas_exe, doas_flags, default_cmd)) + self.assertEqual(cmd, """%s -c '%s %s %s -c '"'"'echo %s; %s'"'"''""" % (default_exe, doas_exe, doas_flags, default_exe, play_context.success_key, default_cmd)) play_context.become_method = 'bad' self.assertRaises(AnsibleError, play_context.make_become_cmd, cmd=default_cmd, executable="/bin/bash")