summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRicardo Carrillo Cruz <ricardo.carrillo.cruz@gmail.com>2018-05-16 14:59:01 +0200
committerGitHub <noreply@github.com>2018-05-16 14:59:01 +0200
commit62e1c14edc408e3f0bdd82c6bb264a969ce98fe9 (patch)
tree0619d51cce31bc5fe6f2f6f13489bc3adc33214c /lib
parent865f2c5990554e51e412f8c3748ff0e6fc29f59c (diff)
downloadansible-62e1c14edc408e3f0bdd82c6bb264a969ce98fe9.tar.gz
Pull persistent connection parameters via get_option (#39367)
* WIP Pull persistent connection parameters via get_option * Fix pep8 * Add use_persistent_connection setting to paramiko_ssh plugin * Add vars section to persistent_command_timeout setting and prevail provider values over config manager * Use persistent_command_timeout on network_cli instead of timeout * Fix unit tests If we don't call loader to get network_cli, then _load_name is never set and we get KeyError. * Pull persistent_command_timeout via config manager for ios connection local * Pull persistent_command_timeout via config manager on connection local
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/executor/task_executor.py2
-rw-r--r--lib/ansible/plugins/action/eos.py5
-rw-r--r--lib/ansible/plugins/action/ios.py5
-rw-r--r--lib/ansible/plugins/action/iosxr.py5
-rw-r--r--lib/ansible/plugins/action/junos.py5
-rw-r--r--lib/ansible/plugins/action/nxos.py5
-rw-r--r--lib/ansible/plugins/action/vyos.py5
-rw-r--r--lib/ansible/plugins/connection/network_cli.py6
-rw-r--r--lib/ansible/plugins/connection/paramiko_ssh.py12
-rw-r--r--lib/ansible/plugins/connection/persistent.py24
10 files changed, 57 insertions, 17 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 2b49e2cf85..6ce6441ebf 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -810,7 +810,7 @@ class TaskExecutor:
self._play_context.set_options_from_plugin(connection)
if any(((connection.supports_persistence and C.USE_PERSISTENT_CONNECTIONS), connection.force_persistence)):
- self._play_context.timeout = C.PERSISTENT_COMMAND_TIMEOUT
+ self._play_context.timeout = connection.get_option('persistent_command_timeout')
display.vvvv('attempting to start connection', host=self._play_context.remote_addr)
display.vvvv('using connection plugin %s' % connection.transport, host=self._play_context.remote_addr)
socket_path = self._start_connection()
diff --git a/lib/ansible/plugins/action/eos.py b/lib/ansible/plugins/action/eos.py
index c7a25cd3d2..9f396aaf85 100644
--- a/lib/ansible/plugins/action/eos.py
+++ b/lib/ansible/plugins/action/eos.py
@@ -66,7 +66,7 @@ class ActionModule(_ActionModule):
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -75,6 +75,9 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py
index 1a50166086..6fbe7dba9f 100644
--- a/lib/ansible/plugins/action/ios.py
+++ b/lib/ansible/plugins/action/ios.py
@@ -58,7 +58,7 @@ class ActionModule(_ActionModule):
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -67,6 +67,9 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py
index 6c16a110c5..8b9e5eae82 100644
--- a/lib/ansible/plugins/action/iosxr.py
+++ b/lib/ansible/plugins/action/iosxr.py
@@ -61,11 +61,14 @@ class ActionModule(_ActionModule):
pc.port = int(provider['port'] or self._play_context.port or 22)
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/junos.py b/lib/ansible/plugins/action/junos.py
index 87b2d6e234..5f3cbafa3f 100644
--- a/lib/ansible/plugins/action/junos.py
+++ b/lib/ansible/plugins/action/junos.py
@@ -72,11 +72,14 @@ class ActionModule(_ActionModule):
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py
index d98afa256f..4b3663f8b3 100644
--- a/lib/ansible/plugins/action/nxos.py
+++ b/lib/ansible/plugins/action/nxos.py
@@ -69,7 +69,7 @@ class ActionModule(_ActionModule):
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -78,6 +78,9 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py
index 102c6ecb11..383db5ed66 100644
--- a/lib/ansible/plugins/action/vyos.py
+++ b/lib/ansible/plugins/action/vyos.py
@@ -58,11 +58,14 @@ class ActionModule(_ActionModule):
pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
- pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
+ pc.timeout = int(provider['timeout']) if provider['timeout'] else None
display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ if connection._play_context.timeout is None:
+ connection._play_context.timeout = connection.get_option('persistent_command_timeout')
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py
index d5e9ca76b6..43208465de 100644
--- a/lib/ansible/plugins/connection/network_cli.py
+++ b/lib/ansible/plugins/connection/network_cli.py
@@ -151,8 +151,8 @@ options:
close
default: 10
ini:
- section: persistent_connection
- key: persistent_command_timeout
+ - section: persistent_connection
+ key: command_timeout
env:
- name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
"""
@@ -298,7 +298,7 @@ class Connection(ConnectionBase):
display.vvvv('ssh connection done, setting terminal', host=self._play_context.remote_addr)
self._ssh_shell = ssh.ssh.invoke_shell()
- self._ssh_shell.settimeout(self._play_context.timeout)
+ self._ssh_shell.settimeout(self.get_option('persistent_command_timeout'))
network_os = self._play_context.network_os
if not network_os:
diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py
index 60f96a7f2b..6ff21434c7 100644
--- a/lib/ansible/plugins/connection/paramiko_ssh.py
+++ b/lib/ansible/plugins/connection/paramiko_ssh.py
@@ -114,8 +114,16 @@ DOCUMENTATION = """
version_added: '2.5'
- name: ansible_paramiko_host_key_checking
version_added: '2.5'
+ use_persistent_connections:
+ description: 'Toggles the use of persistence for connections'
+ type: boolean
+ default: False
+ env:
+ - name: ANSIBLE_USE_PERSISTENT_CONNECTIONS
+ ini:
+ - section: defaults
+ key: use_persistent_connections
# TODO:
-#C.USE_PERSISTENT_CONNECTIONS:
#timeout=self._play_context.timeout,
"""
@@ -188,7 +196,7 @@ class MyAddPolicy(object):
fingerprint = hexlify(key.get_fingerprint())
ktype = key.get_name()
- if C.USE_PERSISTENT_CONNECTIONS or self.connection.force_persistence:
+ if self.connection.get_option('use_persistent_connections') or self.connection.force_persistence:
# don't print the prompt string since the user cannot respond
# to the question anyway
raise AnsibleError(AUTHENTICITY_MSG[1:92] % (hostname, ktype, fingerprint))
diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py
index ac2406f4c1..1eb4d2d6aa 100644
--- a/lib/ansible/plugins/connection/persistent.py
+++ b/lib/ansible/plugins/connection/persistent.py
@@ -6,12 +6,26 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = """
- author: Ansible Core Team
- connection: persistent
- short_description: Use a persistent unix socket for connection
+author: Ansible Core Team
+connection: persistent
+short_description: Use a persistent unix socket for connection
+description:
+ - This is a helper plugin to allow making other connections persistent.
+version_added: "2.3"
+options:
+ persistent_command_timeout:
+ type: int
description:
- - This is a helper plugin to allow making other connections persistent.
- version_added: "2.3"
+ - Configures, in seconds, the amount of time to wait for a command to
+ return from the remote device. If this timer is exceeded before the
+ command returns, the connection plugin will raise an exception and
+ close
+ default: 10
+ ini:
+ - section: persistent_connection
+ key: command_timeout
+ env:
+ - name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
"""
import os
import pty