Moving ConnectionInformation -> PlayContext

Also making PlayContext a child class of the Playbook Base class,
which gives it access to all of the FieldAttribute code to ensure
field values are correctly typed after post_validation

Fixes #11381
This commit is contained in:
James Cammarata 2015-07-21 12:12:22 -04:00
commit e64989beb4
36 changed files with 477 additions and 459 deletions

View file

@ -129,7 +129,7 @@ class Connection(ConnectionBase):
return 'paramiko'
def _cache_key(self):
return "%s__%s__" % (self._connection_info.remote_addr, self._connection_info.remote_user)
return "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
def _connect(self):
cache_key = self._cache_key()
@ -145,8 +145,8 @@ class Connection(ConnectionBase):
if not HAVE_PARAMIKO:
raise AnsibleError("paramiko is not installed")
port = self._connection_info.port or 22
self._display.vvv("ESTABLISH CONNECTION FOR USER: %s on PORT %s TO %s" % (self._connection_info.remote_user, port, self._connection_info.remote_addr), host=self._connection_info.remote_addr)
port = self._play_context.port or 22
self._display.vvv("ESTABLISH 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)
ssh = paramiko.SSHClient()
@ -159,22 +159,22 @@ class Connection(ConnectionBase):
allow_agent = True
if self._connection_info.password is not None:
if self._play_context.password is not None:
allow_agent = False
try:
key_filename = None
if self._connection_info.private_key_file:
key_filename = os.path.expanduser(self._connection_info.private_key_file)
if self._play_context.private_key_file:
key_filename = os.path.expanduser(self._play_context.private_key_file)
ssh.connect(
self._connection_info.remote_addr,
username=self._connection_info.remote_user,
self._play_context.remote_addr,
username=self._play_context.remote_user,
allow_agent=allow_agent,
look_for_keys=True,
key_filename=key_filename,
password=self._connection_info.password,
timeout=self._connection_info.timeout,
password=self._play_context.password,
timeout=self._play_context.timeout,
port=port,
)
except Exception as e:
@ -183,7 +183,7 @@ class Connection(ConnectionBase):
raise AnsibleError("paramiko version issue, please upgrade paramiko on the machine running ansible")
elif "Private key file is encrypted" in msg:
msg = 'ssh %s@%s:%s : %s\nTo connect as a different user, use -u <username>.' % (
self._connection_info.remote_user, self._connection_info.remote_addr, port, msg)
self._play_context.remote_user, self._play_context.remote_addr, port, msg)
raise AnsibleConnectionFailure(msg)
else:
raise AnsibleConnectionFailure(msg)
@ -215,7 +215,7 @@ class Connection(ConnectionBase):
if C.PARAMIKO_PTY:
chan.get_pty(term=os.getenv('TERM', 'vt100'), width=int(os.getenv('COLUMNS', 0)), height=int(os.getenv('LINES', 0)))
self._display.vvv("EXEC %s" % cmd, host=self._connection_info.remote_addr)
self._display.vvv("EXEC %s" % cmd, host=self._play_context.remote_addr)
no_prompt_out = ''
no_prompt_err = ''
@ -223,8 +223,8 @@ class Connection(ConnectionBase):
try:
chan.exec_command(cmd)
if self._connection_info.prompt:
if self._connection_info.become and self._connection_info.become_pass:
if self._play_context.prompt:
if self._play_context.become and self._play_context.become_pass:
while True:
debug('Waiting for Privilege Escalation input')
if self.check_become_success(become_output) or self.check_password_prompt(become_output):
@ -240,8 +240,8 @@ class Connection(ConnectionBase):
'closed waiting for password prompt')
become_output += chunk
if not self.check_become_success(become_output):
if self._connection_info.become:
chan.sendall(self._connection_info.become_pass + '\n')
if self._play_context.become:
chan.sendall(self._play_context.become_pass + '\n')
else:
no_prompt_out += become_output
no_prompt_err += become_output
@ -258,7 +258,7 @@ class Connection(ConnectionBase):
super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self._connection_info.remote_addr)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr)
if not os.path.exists(in_path):
raise AnsibleFileNotFound("file or module does not exist: %s" % in_path)
@ -275,7 +275,7 @@ class Connection(ConnectionBase):
def _connect_sftp(self):
cache_key = "%s__%s__" % (self._connection_info.remote_addr, self._connection_info.remote_user)
cache_key = "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
if cache_key in SFTP_CONNECTION_CACHE:
return SFTP_CONNECTION_CACHE[cache_key]
else:
@ -287,7 +287,7 @@ class Connection(ConnectionBase):
super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self._connection_info.remote_addr)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr)
try:
self.sftp = self._connect_sftp()