dzdo prompt fix

fixed tests
dzdo has 2 paths now, with and w/o password
fixes #17838
pull/17847/head
Brian Coca 8 years ago committed by Brian Coca
parent 6008fbd5cf
commit dfff608ceb

@ -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)

@ -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 = (

Loading…
Cancel
Save