1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Revert "use get_optoins instead of play_context for user (#52604)" (#53034)

This reverts commit cf6a92d268.
This commit is contained in:
Brian Coca 2019-02-26 18:01:39 -05:00 committed by GitHub
parent 7360db5956
commit c09d11ad35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -125,26 +125,6 @@ DOCUMENTATION = """
ini: ini:
- section: defaults - section: defaults
key: use_persistent_connections key: use_persistent_connections
port:
description:
- Port on which ssh server is listening on
default: 22
type: int
vars:
- name: ansible_port
- name: ansible_ssh_port
- name: ansible_paramiko_port
version_added: '2.8'
env:
- name: ANSIBLE_REMOTE_PORT
- name: ANSIBLE_PARAMIKO_REMOTE_PORT
version_added: '2.8'
ini:
- key: remote_port
section: defaults
- key: remote_port
section: paramiko_connection
version_added: '2.8'
# TODO: # TODO:
#timeout=self._play_context.timeout, #timeout=self._play_context.timeout,
""" """
@ -162,6 +142,7 @@ from termios import tcflush, TCIFLUSH
from distutils.version import LooseVersion from distutils.version import LooseVersion
from binascii import hexlify from binascii import hexlify
from ansible import constants as C
from ansible.errors import ( from ansible.errors import (
AnsibleAuthenticationFailure, AnsibleAuthenticationFailure,
AnsibleConnectionFailure, AnsibleConnectionFailure,
@ -264,7 +245,7 @@ class Connection(ConnectionBase):
_log_channel = None _log_channel = None
def _cache_key(self): def _cache_key(self):
return "%s__%s__" % (self._play_context.remote_addr, self.get_option('remote_user')) return "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
def _connect(self): def _connect(self):
cache_key = self._cache_key() cache_key = self._cache_key()
@ -309,7 +290,7 @@ class Connection(ConnectionBase):
replacers = { replacers = {
'%h': self._play_context.remote_addr, '%h': self._play_context.remote_addr,
'%p': port, '%p': port,
'%r': self.get_option('remote_user') '%r': self._play_context.remote_user
} }
for find, replace in replacers.items(): for find, replace in replacers.items():
proxy_command = proxy_command.replace(find, str(replace)) proxy_command = proxy_command.replace(find, str(replace))
@ -329,8 +310,8 @@ class Connection(ConnectionBase):
if not HAVE_PARAMIKO: if not HAVE_PARAMIKO:
raise AnsibleError("paramiko is not installed: %s" % to_native(PARAMIKO_IMP_ERR)) raise AnsibleError("paramiko is not installed: %s" % to_native(PARAMIKO_IMP_ERR))
port = self.get_option('port') port = self._play_context.port or 22
display.vvv("ESTABLISH PARAMIKO SSH CONNECTION FOR USER: %s on PORT %s TO %s" % (self.get_option('remote_user'), port, self._play_context.remote_addr), display.vvv("ESTABLISH PARAMIKO SSH CONNECTION FOR USER: %s on PORT %s TO %s" % (self._play_context.remote_user, port, self._play_context.remote_addr),
host=self._play_context.remote_addr) host=self._play_context.remote_addr)
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
@ -371,7 +352,7 @@ class Connection(ConnectionBase):
ssh.connect( ssh.connect(
self._play_context.remote_addr.lower(), self._play_context.remote_addr.lower(),
username=self.get_option('remote_user'), username=self._play_context.remote_user,
allow_agent=allow_agent, allow_agent=allow_agent,
look_for_keys=self.get_option('look_for_keys'), look_for_keys=self.get_option('look_for_keys'),
key_filename=key_filename, key_filename=key_filename,
@ -391,7 +372,7 @@ class Connection(ConnectionBase):
raise AnsibleError("paramiko version issue, please upgrade paramiko on the machine running ansible") raise AnsibleError("paramiko version issue, please upgrade paramiko on the machine running ansible")
elif u"Private key file is encrypted" in msg: elif u"Private key file is encrypted" in msg:
msg = 'ssh %s@%s:%s : %s\nTo connect as a different user, use -u <username>.' % ( msg = 'ssh %s@%s:%s : %s\nTo connect as a different user, use -u <username>.' % (
self.get_option('remote_user'), self._play_context.remote_addr, port, msg) self._play_context.remote_user, self._play_context.remote_addr, port, msg)
raise AnsibleConnectionFailure(msg) raise AnsibleConnectionFailure(msg)
else: else:
raise AnsibleConnectionFailure(msg) raise AnsibleConnectionFailure(msg)
@ -444,7 +425,7 @@ class Connection(ConnectionBase):
display.debug("chunk is: %s" % chunk) display.debug("chunk is: %s" % chunk)
if not chunk: if not chunk:
if b'unknown user' in become_output: if b'unknown user' in become_output:
raise AnsibleError('user %s does not exist' % self._.become_user) raise AnsibleError('user %s does not exist' % self._play_context.become_user)
else: else:
break break
# raise AnsibleError('ssh connection closed waiting for password prompt') # raise AnsibleError('ssh connection closed waiting for password prompt')
@ -498,7 +479,7 @@ class Connection(ConnectionBase):
def _connect_sftp(self): def _connect_sftp(self):
cache_key = "%s__%s__" % (self._play_context.remote_addr, self.get_option('remote_user')) cache_key = "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
if cache_key in SFTP_CONNECTION_CACHE: if cache_key in SFTP_CONNECTION_CACHE:
return SFTP_CONNECTION_CACHE[cache_key] return SFTP_CONNECTION_CACHE[cache_key]
else: else: