become_method: make dzdo more like sudo (#47946)

dzdo is basically a drop-in replacement for sudo and supports the same
command line options.

There is no become_flags set for dzdo like there is for sudo, so users
will have to set that separately to have exactly the same functionality.
This commit is contained in:
James Cassell 2018-12-04 18:24:32 -05:00 committed by ansibot
commit 2bd6b1415b
2 changed files with 6 additions and 2 deletions

View file

@ -539,11 +539,15 @@ class PlayContext(Base):
becomecmd = '%s %s %s -c %s' % (exe, flags, executable, success_cmd)
elif self.become_method == 'dzdo':
# If we have a password, we run dzdo with a randomly-generated
# prompt set using -p. Otherwise we run it with -n, if
# requested, which makes it fail if it would have prompted for a
# password.
exe = self.become_exe or 'dzdo'
if self.become_pass:
prompt = '[dzdo via ansible, key=%s] password: ' % randbits
becomecmd = '%s %s -p %s -u %s %s' % (exe, flags, shlex_quote(prompt), self.become_user, command)
becomecmd = '%s %s -p %s -u %s %s' % (exe, flags.replace('-n', ''), shlex_quote(prompt), self.become_user, command)
else:
becomecmd = '%s %s -u %s %s' % (exe, flags, self.become_user, command)