Provide nice error when the shell plugin is incompatible with the con figured become plugin (#60441)

* Provide nice error when the shell plugin is incompatible with the configured become plugin. Fixes #57770

* Add todo

* Add missing import
This commit is contained in:
Matt Martz 2019-08-13 09:37:53 -05:00 committed by GitHub
parent 6b5c7f7c42
commit ba81084a49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- become - Provide nice error when the shell plugin is incompatible with the configured become plugin
(https://github.com/ansible/ansible/issues/57770)

View file

@ -9,6 +9,7 @@ from random import choice
from string import ascii_lowercase from string import ascii_lowercase
from gettext import dgettext from gettext import dgettext
from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_bytes
from ansible.plugins import AnsiblePlugin from ansible.plugins import AnsiblePlugin
@ -49,7 +50,11 @@ class BecomeBase(AnsiblePlugin):
if not all((cmd, shell, self.success)): if not all((cmd, shell, self.success)):
return cmd return cmd
try:
cmd = shlex_quote('%s %s %s %s' % (shell.ECHO, self.success, shell.COMMAND_SEP, cmd)) cmd = shlex_quote('%s %s %s %s' % (shell.ECHO, self.success, shell.COMMAND_SEP, cmd))
except AttributeError:
# TODO: This should probably become some more robust functionlity used to detect incompat
raise AnsibleError('The %s shell family is incompatible with the %s become plugin' % (shell.SHELL_FAMILY, self.name))
exe = getattr(shell, 'executable', None) exe = getattr(shell, 'executable', None)
if exe and not noexe: if exe and not noexe:
cmd = '%s -c %s' % (exe, cmd) cmd = '%s -c %s' % (exe, cmd)