From 5144ee226ead9e77120e48b2d898c3200ae5d73c Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 19 Jan 2016 14:05:29 -0500 Subject: [PATCH] adds private key file support to shell shared module This commit provides an argument to provide a path to the private key file. This will allow paramiko to use the key file as opposed to only username / password combinations for CLI connections. --- lib/ansible/module_utils/shell.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/shell.py b/lib/ansible/module_utils/shell.py index 0107911ba0..13506c4322 100644 --- a/lib/ansible/module_utils/shell.py +++ b/lib/ansible/module_utils/shell.py @@ -31,7 +31,7 @@ except ImportError: ANSI_RE = re.compile(r'(\x1b\[\?1h\x1b=)') CLI_PROMPTS_RE = [ - re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*[>|#](?:\s*)$'), + re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*[>|#|%](?:\s*)$'), re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*\(.+\)#(?:\s*)$') ] @@ -84,15 +84,18 @@ class Shell(object): self.errors.extend(CLI_ERRORS_RE) def open(self, host, port=22, username=None, password=None, - timeout=10, key_filename=None): + timeout=10, key_filename=None, pkey=None, look_for_keys=None): self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - use_keys = password is None + # unless explicitly set, disable look for keys if a password is + # present. this changes the default search order paramiko implements + if not look_for_keys: + look_for_keys = password is None self.ssh.connect(host, port=port, username=username, password=password, - timeout=timeout, allow_agent=use_keys, look_for_keys=use_keys, + timeout=timeout, look_for_keys=look_for_keys, pkey=pkey, key_filename=key_filename) self.shell = self.ssh.invoke_shell()