From c55adc9ac9d4e67aeeb1b0e1d58e4e013538f164 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 4 Jul 2013 16:47:17 -0400 Subject: [PATCH] Default to 'smart' transport, which will use OpenSSH if it can support ControlPersist. --- examples/ansible.cfg | 2 +- lib/ansible/constants.py | 2 +- lib/ansible/runner/__init__.py | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/ansible.cfg b/examples/ansible.cfg index d505bf0ccf3..0e9e91de14a 100644 --- a/examples/ansible.cfg +++ b/examples/ansible.cfg @@ -19,7 +19,7 @@ poll_interval = 15 sudo_user = root #ask_sudo_pass = True #ask_pass = True -transport = paramiko +transport = smart remote_port = 22 # uncomment this to disable SSH key host checking diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 82f5d7a7dfe..3351c6f661b 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -104,7 +104,7 @@ DEFAULT_PRIVATE_KEY_FILE = shell_expand_path(get_config(p, DEFAULTS, 'private_k DEFAULT_SUDO_USER = get_config(p, DEFAULTS, 'sudo_user', 'ANSIBLE_SUDO_USER', 'root') DEFAULT_ASK_SUDO_PASS = get_config(p, DEFAULTS, 'ask_sudo_pass', 'ANSIBLE_ASK_SUDO_PASS', False, boolean=True) 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_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE_TRANSPORT', 'smart') DEFAULT_SCP_IF_SSH = get_config(p, 'ssh_connection', 'scp_if_ssh', 'ANSIBLE_SCP_IF_SSH', False, boolean=True) DEFAULT_MANAGED_STR = get_config(p, DEFAULTS, 'ansible_managed', None, 'Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}') DEFAULT_SYSLOG_FACILITY = get_config(p, DEFAULTS, 'syslog_facility', 'ANSIBLE_SYSLOG_FACILITY', 'LOG_USER') diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 7e0bf0de029..93c1070889e 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -31,6 +31,7 @@ import sys import shlex import pipes import jinja2 +import subprocess import ansible.constants as C import ansible.inventory @@ -169,9 +170,19 @@ class Runner(object): self.environment = environment self.complex_args = complex_args self.error_on_undefined_vars = error_on_undefined_vars - self.callbacks.runner = self + # if the transport is 'smart' see if SSH can support ControlPersist if not use paramiko + # 'smart' is the default since 1.2.1/1.3 + if self.transport == 'smart': + cmd = subprocess.Popen(['ssh','-o','ControlPersist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = cmd.communicate() + if "Bad configuration option" in err: + self.transport = "paramiko" + else: + self.transport = "ssh" + + # misc housekeeping if subset and self.inventory._subset is None: # don't override subset when passed from playbook