Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Paramiko SSH Config file #1026

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ansible/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def shell_expand_path(path):
DEFAULT_SUDO_USER = get_config(p, DEFAULTS, 'sudo_user', 'ANSIBLE_SUDO_USER', 'root')
DEFAULT_REMOTE_PORT = int(get_config(p, DEFAULTS, 'remote_port', 'ANSIBLE_REMOTE_PORT', 22))
DEFAULT_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE_TRANSPORT', 'paramiko')
DEFAULT_SSHCONFIGFILE = get_config(p, DEFAULTS, 'sshconfigfile', 'ANSIBLE_SSHCONFIGFILE', '~/.ssh/config')

# non-configurable things
DEFAULT_REMOTE_PASS = None
Expand Down
1 change: 1 addition & 0 deletions lib/ansible/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self,
basedir=None, # directory of playbook, if applicable
setup_cache=None, # used to share fact data w/ other tasks
transport=C.DEFAULT_TRANSPORT, # 'ssh', 'paramiko', 'local'
sshconfigfile=C.DEFAULT_SSHCONFIGFILE, # ssh default config file
conditional='True', # run only if this fact expression evals to true
callbacks=None, # used for output
sudo=False, # whether to run sudo or not
Expand Down
21 changes: 18 additions & 3 deletions lib/ansible/runner/connection_plugins/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,25 @@ def connect(self):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

scl = False
sshconfigfile = C.DEFAULT_SSHCONFIGFILE
homedir = os.path.expanduser('~')
sshconfigfile = (sshconfigfile).replace('~',homedir)
config = paramiko.SSHConfig()
if(os.path.exists(sshconfigfile)):
config.parse(open(sshconfigfile))
scl = config.lookup(self.host)

try:
ssh.connect(self.host, username=user, allow_agent=True, look_for_keys=True,
key_filename=self.runner.private_key_file, password=self.runner.remote_pass,
timeout=self.runner.timeout, port=self.port)
if(scl):
keyfile = (scl['identityfile']).replace('~',homedir)
ssh.connect(scl['hostname'], username=scl['user'], allow_agent=True, look_for_keys=True,
key_filename=keyfile, password=self.runner.remote_pass,
timeout=self.runner.timeout, port=scl['port'])
else:
ssh.connect(self.host, username=user, allow_agent=True, look_for_keys=True,
key_filename=self.runner.private_key_file, password=self.runner.remote_pass,
timeout=self.runner.timeout, port=self.port)
except Exception, e:
msg = str(e)
if "PID check failed" in msg:
Expand Down