avoid constant checking controlpersist (#69910)

* avoid constant checking controlpersist
pull/69967/head
Brian Coca 5 years ago committed by GitHub
parent c41a160951
commit a64418c2b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- optimize 'smart' detection from being run over and over and preferably do it at config time.

@ -135,7 +135,7 @@ ANSIBLE_SSH_CONTROL_PATH_DIR:
- {key: control_path_dir, section: ssh_connection} - {key: control_path_dir, section: ssh_connection}
yaml: {key: ssh_connection.control_path_dir} yaml: {key: ssh_connection.control_path_dir}
ANSIBLE_SSH_EXECUTABLE: ANSIBLE_SSH_EXECUTABLE:
# TODO: move to ssh plugin # TODO: move to ssh plugin, note that ssh_utils refs this and needs to be updated if removed
default: ssh default: ssh
description: description:
- This defines the location of the ssh binary. It defaults to `ssh` which will use the first ssh binary available in $PATH. - This defines the location of the ssh binary. It defaults to `ssh` which will use the first ssh binary available in $PATH.
@ -1162,6 +1162,7 @@ DEFAULT_TIMEOUT:
- {key: timeout, section: defaults} - {key: timeout, section: defaults}
type: integer type: integer
DEFAULT_TRANSPORT: DEFAULT_TRANSPORT:
# note that ssh_utils refs this and needs to be updated if removed
name: Connection plugin name: Connection plugin
default: smart default: smart
description: "Default connection plugin to use, the 'smart' option will toggle between 'ssh' and 'paramiko' depending on controller OS and ssh versions" description: "Default connection plugin to use, the 'smart' option will toggle between 'ssh' and 'paramiko' depending on controller OS and ssh versions"

@ -12,11 +12,11 @@ from ast import literal_eval
from jinja2 import Template from jinja2 import Template
from string import ascii_letters, digits from string import ascii_letters, digits
from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.common.collections import Sequence from ansible.module_utils.common.collections import Sequence
from ansible.module_utils.parsing.convert_bool import boolean, BOOLEANS_TRUE from ansible.module_utils.parsing.convert_bool import boolean, BOOLEANS_TRUE
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
def _warning(msg): def _warning(msg):

@ -31,7 +31,7 @@ from ansible.playbook import Playbook
from ansible.template import Templar from ansible.template import Templar
from ansible.utils.helpers import pct_to_int from ansible.utils.helpers import pct_to_int
from ansible.utils.path import makedirs_safe from ansible.utils.path import makedirs_safe
from ansible.utils.ssh_functions import check_for_controlpersist from ansible.utils.ssh_functions import set_default_transport
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()
@ -70,7 +70,7 @@ class PlaybookExecutor:
# in inventory is also cached. We can't do this caching at the point # in inventory is also cached. We can't do this caching at the point
# where it is used (in task_executor) because that is post-fork and # where it is used (in task_executor) because that is post-fork and
# therefore would be discarded after every task. # therefore would be discarded after every task.
check_for_controlpersist(C.ANSIBLE_SSH_EXECUTABLE) set_default_transport()
def run(self): def run(self):
''' '''

@ -22,7 +22,9 @@ __metaclass__ = type
import subprocess import subprocess
from ansible import constants as C
from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_bytes
from ansible.module_utils.compat.paramiko import paramiko
_HAS_CONTROLPERSIST = {} _HAS_CONTROLPERSIST = {}
@ -47,3 +49,17 @@ def check_for_controlpersist(ssh_executable):
_HAS_CONTROLPERSIST[ssh_executable] = has_cp _HAS_CONTROLPERSIST[ssh_executable] = has_cp
return has_cp return has_cp
def set_default_transport():
# deal with 'smart' connection .. one time ..
if C.DEFAULT_TRANSPORT == 'smart':
# TODO: check if we can deprecate this as ssh w/o control persist should
# not be as common anymore.
# see if SSH can support ControlPersist if not use paramiko
if not check_for_controlpersist(C.ANSIBLE_SSH_EXECUTABLE) and paramiko is not None:
C.DEFAULT_TRANSPORT = "paramiko"
else:
C.DEFAULT_TRANSPORT = "ssh"

Loading…
Cancel
Save