diff --git a/changelogs/fragments/57770-become-shell-compat.yml b/changelogs/fragments/57770-become-shell-compat.yml new file mode 100644 index 00000000000..b8e771be70b --- /dev/null +++ b/changelogs/fragments/57770-become-shell-compat.yml @@ -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) diff --git a/lib/ansible/plugins/become/__init__.py b/lib/ansible/plugins/become/__init__.py index 17ed0ee34f0..6f7e1d19509 100644 --- a/lib/ansible/plugins/become/__init__.py +++ b/lib/ansible/plugins/become/__init__.py @@ -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)