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:
parent
6b5c7f7c42
commit
ba81084a49
2 changed files with 9 additions and 1 deletions
3
changelogs/fragments/57770-become-shell-compat.yml
Normal file
3
changelogs/fragments/57770-become-shell-compat.yml
Normal 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)
|
|
@ -9,6 +9,7 @@ from random import choice
|
|||
from string import ascii_lowercase
|
||||
from gettext import dgettext
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins import AnsiblePlugin
|
||||
|
@ -49,7 +50,11 @@ class BecomeBase(AnsiblePlugin):
|
|||
if not all((cmd, shell, self.success)):
|
||||
return cmd
|
||||
|
||||
cmd = shlex_quote('%s %s %s %s' % (shell.ECHO, self.success, shell.COMMAND_SEP, cmd))
|
||||
try:
|
||||
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)
|
||||
if exe and not noexe:
|
||||
cmd = '%s -c %s' % (exe, cmd)
|
||||
|
|
Loading…
Reference in a new issue