diff options
author | Nathaniel Case <this.is@nathanielca.se> | 2018-05-17 18:25:44 -0400 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2018-05-17 15:25:44 -0700 |
commit | 864fd7c53e45703554bb6de608fe13a2200b6aa0 (patch) | |
tree | 7a577e13d5863824d2bea6ce7f36a6a4ca39b816 | |
parent | 84f9303c524e3110dc50199e010ffc43ce5d9e18 (diff) | |
download | ansible-864fd7c53e45703554bb6de608fe13a2200b6aa0.tar.gz |
Local remote 2.5 backport (#40363)
* Don't rewrite remote paths when remote is secretly local
* Remote overriding is configurable in connection
* Use c.DEFAULT_LOCAL_TMP instead of remote_tmp
* Remove remote_is_local from ConnectionBase
* remote_is_local->_remote_is_local
* Add warning signs to _remote_is_local and explanatory comments to its use
-rw-r--r-- | lib/ansible/plugins/action/__init__.py | 15 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/netconf.py | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/network_cli.py | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index c5cacfe36f..8cb0d35d06 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -246,7 +246,13 @@ class ActionBase(with_metaclass(ABCMeta, object)): # deal with tmpdir creation basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48)) use_system_tmp = bool(self._play_context.become and self._play_context.become_user not in admin_users) - tmpdir = self._remote_expand_user(remote_tmp, sudoable=False) + # Network connection plugins (network_cli, netconf, etc.) execute on the controller, rather than the remote host. + # As such, we want to avoid using remote_user for paths as remote_user may not line up with the local user + # This is a hack and should be solved by more intelligent handling of remote_tmp in 2.7 + if getattr(self._connection, '_remote_is_local', False): + tmpdir = C.DEFAULT_LOCAL_TMP + else: + tmpdir = self._remote_expand_user(remote_tmp, sudoable=False) cmd = self._connection._shell.mkdtemp(basefile=basefile, system=use_system_tmp, tmpdir=tmpdir) result = self._low_level_execute_command(cmd, sudoable=False) @@ -568,7 +574,12 @@ class ActionBase(with_metaclass(ABCMeta, object)): expand_path = split_path[0] if expand_path == '~': - if sudoable and self._play_context.become and self._play_context.become_user: + # Network connection plugins (network_cli, netconf, etc.) execute on the controller, rather than the remote host. + # As such, we want to avoid using remote_user for paths as remote_user may not line up with the local user + # This is a hack and should be solved by more intelligent handling of remote_tmp in 2.7 + if getattr(self._connection, '_remote_is_local', False): + pass + elif 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 diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py index 29aa2d2ef0..83cee4ef04 100644 --- a/lib/ansible/plugins/connection/netconf.py +++ b/lib/ansible/plugins/connection/netconf.py @@ -170,6 +170,8 @@ class Connection(ConnectionBase): transport = 'netconf' has_pipelining = False force_persistence = True + # Do not use _remote_is_local in other connections + _remote_is_local = True 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/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index e5568d659c..68add9b38c 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -188,6 +188,8 @@ class Connection(ConnectionBase): transport = 'network_cli' has_pipelining = True force_persistence = True + # Do not use _remote_is_local in other connections + _remote_is_local = True def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) |