diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 069d411f70..b038862b20 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -562,8 +562,11 @@ class PlayContext(Base): elif self.become_method == 'dzdo': exe = self.become_exe or 'dzdo' - - becomecmd = '%s -u %s %s' % (exe, self.become_user, command) + if self.become_pass: + prompt = '[dzdo via ansible, key=%s] password: ' % randbits + becomecmd = '%s -p %s -u %s %s' % (exe, pipes.quote(prompt), self.become_user, command) + else: + becomecmd = '%s -u %s %s' % (exe, self.become_user, command) 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 9e94f615bb..109d06934f 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import os +import pipes from ansible.compat.tests import unittest from ansible.compat.tests.mock import patch, MagicMock @@ -177,6 +178,11 @@ class TestPlayContext(unittest.TestCase): cmd = play_context.make_become_cmd(cmd=default_cmd, executable="/bin/bash") self.assertEqual(cmd, """%s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, play_context.become_user, default_exe, play_context.success_key, default_cmd)) + play_context.become_pass = 'testpass' + play_context.become_method = 'dzdo' + cmd = play_context.make_become_cmd(cmd=default_cmd, executable="/bin/bash") + self.assertEqual(cmd, """%s -p %s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, pipes.quote(play_context.prompt), play_context.become_user, default_exe, play_context.success_key, default_cmd)) + class TestTaskAndVariableOverrride(unittest.TestCase): inventory_vars = (