From cc1c7c63db77b38f7a5276f61a7f7897ce6217f4 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 11 Apr 2018 11:53:05 -0400 Subject: [PATCH] ensure 'home' translations (#36755) * ensure 'home' translations * removed slash as it created issues on diff plats --- lib/ansible/plugins/action/__init__.py | 3 +++ lib/ansible/plugins/connection/__init__.py | 2 ++ lib/ansible/plugins/connection/chroot.py | 2 ++ lib/ansible/plugins/connection/libvirt_lxc.py | 1 + lib/ansible/plugins/connection/lxc.py | 1 + lib/ansible/plugins/connection/lxd.py | 1 + 6 files changed, 10 insertions(+) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index eb117f6752e..ca1d339ed2b 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -569,6 +569,9 @@ class ActionBase(with_metaclass(ABCMeta, object)): 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 '' # use shell to construct appropriate command and execute cmd = self._connection._shell.expand_user(expand_path) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index 0e77f9722fd..536925abfc9 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -60,6 +60,8 @@ class ConnectionBase(AnsiblePlugin): supports_persistence = False force_persistence = False + default_user = None + def __init__(self, play_context, new_stdin, shell=None, *args, **kwargs): super(ConnectionBase, self).__init__() diff --git a/lib/ansible/plugins/connection/chroot.py b/lib/ansible/plugins/connection/chroot.py index e0b5a1ed5dd..abf0d178a33 100644 --- a/lib/ansible/plugins/connection/chroot.py +++ b/lib/ansible/plugins/connection/chroot.py @@ -65,6 +65,8 @@ class Connection(ConnectionBase): # Have to look into that before re-enabling this become_methods = frozenset(C.BECOME_METHODS).difference(('su',)) + default_user = 'root' + def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) diff --git a/lib/ansible/plugins/connection/libvirt_lxc.py b/lib/ansible/plugins/connection/libvirt_lxc.py index 0cc8940bb7b..c731e71ad1c 100644 --- a/lib/ansible/plugins/connection/libvirt_lxc.py +++ b/lib/ansible/plugins/connection/libvirt_lxc.py @@ -54,6 +54,7 @@ class Connection(ConnectionBase): # checksums (so copy, for instance, doesn't work right) # Have to look into that before re-enabling this become_methods = frozenset(C.BECOME_METHODS).difference(('su',)) + default_user = 'root' def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) diff --git a/lib/ansible/plugins/connection/lxc.py b/lib/ansible/plugins/connection/lxc.py index a8af7785e98..5219b28d680 100644 --- a/lib/ansible/plugins/connection/lxc.py +++ b/lib/ansible/plugins/connection/lxc.py @@ -55,6 +55,7 @@ class Connection(ConnectionBase): transport = 'lxc' has_pipelining = True become_methods = frozenset(C.BECOME_METHODS) + default_user = 'root' def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) diff --git a/lib/ansible/plugins/connection/lxd.py b/lib/ansible/plugins/connection/lxd.py index 9cc8b8929cd..84d32b9b272 100644 --- a/lib/ansible/plugins/connection/lxd.py +++ b/lib/ansible/plugins/connection/lxd.py @@ -43,6 +43,7 @@ class Connection(ConnectionBase): transport = "lxd" has_pipelining = True + default_user = 'root' def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)