From ba81084a499676e625ee8ea404016e896cee2e7b Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 13 Aug 2019 09:37:53 -0500 Subject: [PATCH] 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 --- changelogs/fragments/57770-become-shell-compat.yml | 3 +++ lib/ansible/plugins/become/__init__.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/57770-become-shell-compat.yml 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)