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.
pull/48703/head
James Cassell 6 years ago committed by ansibot
parent d06cd869b8
commit 2bd6b1415b

@ -76,7 +76,7 @@ BECOME_ERROR_STRINGS = {
'pbrun': '', 'pbrun': '',
'pfexec': '', 'pfexec': '',
'doas': 'Permission denied', 'doas': 'Permission denied',
'dzdo': '', 'dzdo': 'Sorry, try again.',
'ksu': 'Password incorrect', 'ksu': 'Password incorrect',
'pmrun': 'You are not permitted to run this command', 'pmrun': 'You are not permitted to run this command',
'enable': '', 'enable': '',

@ -539,11 +539,15 @@ class PlayContext(Base):
becomecmd = '%s %s %s -c %s' % (exe, flags, executable, success_cmd) becomecmd = '%s %s %s -c %s' % (exe, flags, executable, success_cmd)
elif self.become_method == 'dzdo': 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' exe = self.become_exe or 'dzdo'
if self.become_pass: if self.become_pass:
prompt = '[dzdo via ansible, key=%s] password: ' % randbits 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: else:
becomecmd = '%s %s -u %s %s' % (exe, flags, self.become_user, command) becomecmd = '%s %s -u %s %s' % (exe, flags, self.become_user, command)

Loading…
Cancel
Save