From 0a119c391a24b2cbcc145a96fcb5d6d4f2b81704 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Wed, 2 May 2018 22:45:37 +0530 Subject: [PATCH] Only expand '~' based on become_user/remote_user Change brought forward from #00c023e in stable-2.5. Closes #39281 (bug report) Closes #39540 (PR with substantially the same change) --- lib/ansible/plugins/action/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index d6d0d742bd..c5cacfe36f 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -567,11 +567,12 @@ class ActionBase(with_metaclass(ABCMeta, object)): split_path = path.split(os.path.sep, 1) expand_path = split_path[0] - if sudoable and expand_path == '~' and self._play_context.become and self._play_context.become_user: - expand_path = '~%s' % self._play_context.become_user - else: - # use remote user instead, if none set default to current user - expand_path = '~%s' % self._play_context.remote_user or self._connection.default_user or '' + if expand_path == '~': + if sudoable and self._play_context.become and self._play_context.become_user: + expand_path = '~%s' % self._play_context.become_user + else: + # use remote user instead, if none set default to current user + expand_path = '~%s' % self._play_context.remote_user or self._connection.default_user or '' # use shell to construct appropriate command and execute cmd = self._connection._shell.expand_user(expand_path)