From 37f8684330f94b00c08762017da75a66a85d5f17 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 17 Jul 2019 11:17:48 -0400 Subject: [PATCH] if users are None/empty, dont assume sameness (#58875) (cherry picked from commit 4ef2545eb5d661566e06629015967c2d1b8924e3) also fix all cases of none remote/become users (#59397) some cases failed, when defaults were None on the plugins (cherry picked from commit 74ac229fa877572a036eac4b4bfe278f0cd3826f) --- changelogs/fragments/become_none.yml | 2 ++ lib/ansible/plugins/action/__init__.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/become_none.yml diff --git a/changelogs/fragments/become_none.yml b/changelogs/fragments/become_none.yml new file mode 100644 index 00000000000..15f4af63dcb --- /dev/null +++ b/changelogs/fragments/become_none.yml @@ -0,0 +1,2 @@ +bugfixes: + - Do not assume None is equal as connection and become tools can have different unspecified defaults. diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index f633c5c2293..3e0fdf8024b 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -1035,9 +1035,11 @@ class ActionBase(with_metaclass(ABCMeta, object)): display.debug("_low_level_execute_command(): changing cwd to %s for this command" % chdir) cmd = self._connection._shell.append_command('cd %s' % chdir, cmd) - if (sudoable and self._connection.transport != 'network_cli' and self._connection.become and - (C.BECOME_ALLOW_SAME_USER or - self.get_become_option('become_user') != self._get_remote_user())): + ruser = self._get_remote_user() + buser = self.get_become_option('become_user') + if (sudoable and self._connection.become and # if sudoable and have become + self._connection.transport != 'network_cli' and # if not using network_cli + (C.BECOME_ALLOW_SAME_USER or (buser != ruser or not any((ruser, buser))))): # if we allow same user PE or users are different and either is set display.debug("_low_level_execute_command(): using become for this command") cmd = self._connection.become.build_become_command(cmd, self._connection._shell)