ensure 'home' translations (#36755)

* ensure 'home' translations
* removed slash as it created issues on diff plats

(cherry picked from commit cc1c7c63db)

* fixed bug introduced by orig commit, this should only affect single ~ paths
pull/39619/head
Brian Coca 7 years ago
parent d5e8bedfd6
commit 00c023ed3c

@ -0,0 +1,2 @@
bugfixes:
- correctly deal with user homedir (~) translations https://github.com/ansible/ansible/pull/36755

@ -567,8 +567,12 @@ class ActionBase(with_metaclass(ABCMeta, object)):
split_path = path.split(os.path.sep, 1) split_path = path.split(os.path.sep, 1)
expand_path = split_path[0] expand_path = split_path[0]
if sudoable and expand_path == '~' and self._play_context.become and self._play_context.become_user: if expand_path == '~':
if sudoable and self._play_context.become and self._play_context.become_user:
expand_path = '~%s' % 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 # use shell to construct appropriate command and execute
cmd = self._connection._shell.expand_user(expand_path) cmd = self._connection._shell.expand_user(expand_path)

@ -60,6 +60,8 @@ class ConnectionBase(AnsiblePlugin):
supports_persistence = False supports_persistence = False
force_persistence = False force_persistence = False
default_user = None
def __init__(self, play_context, new_stdin, shell=None, *args, **kwargs): def __init__(self, play_context, new_stdin, shell=None, *args, **kwargs):
super(ConnectionBase, self).__init__() super(ConnectionBase, self).__init__()

@ -65,6 +65,8 @@ class Connection(ConnectionBase):
# Have to look into that before re-enabling this # Have to look into that before re-enabling this
become_methods = frozenset(C.BECOME_METHODS).difference(('su',)) become_methods = frozenset(C.BECOME_METHODS).difference(('su',))
default_user = 'root'
def __init__(self, play_context, new_stdin, *args, **kwargs): def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

@ -54,6 +54,7 @@ class Connection(ConnectionBase):
# checksums (so copy, for instance, doesn't work right) # checksums (so copy, for instance, doesn't work right)
# Have to look into that before re-enabling this # Have to look into that before re-enabling this
become_methods = frozenset(C.BECOME_METHODS).difference(('su',)) become_methods = frozenset(C.BECOME_METHODS).difference(('su',))
default_user = 'root'
def __init__(self, play_context, new_stdin, *args, **kwargs): def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

@ -55,6 +55,7 @@ class Connection(ConnectionBase):
transport = 'lxc' transport = 'lxc'
has_pipelining = True has_pipelining = True
become_methods = frozenset(C.BECOME_METHODS) become_methods = frozenset(C.BECOME_METHODS)
default_user = 'root'
def __init__(self, play_context, new_stdin, *args, **kwargs): def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

@ -43,6 +43,7 @@ class Connection(ConnectionBase):
transport = "lxd" transport = "lxd"
has_pipelining = True has_pipelining = True
default_user = 'root'
def __init__(self, play_context, new_stdin, *args, **kwargs): def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

Loading…
Cancel
Save