summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGanesh Nalawade <ganesh634@gmail.com>2018-07-20 06:34:53 +0200
committerGitHub <noreply@github.com>2018-07-20 06:34:53 +0200
commit97d4e5313121b6503e4fcf93ec20f5b9e93f4224 (patch)
tree0003e2cebc132a14a33f9bcf3f3889c5925cd29d
parentAdd missing links for Windows items on the roadmap (#43061) (diff)
downloadansible-97d4e5313121b6503e4fcf93ec20f5b9e93f4224.tar.xz
ansible-97d4e5313121b6503e4fcf93ec20f5b9e93f4224.zip
Support setting persistent command timeout per task basis (#42847)
* Support setting persistent command timeout per task basis Fixes #42200 * Add variable `ansible_command_timeout` to `persistent_command_timeout` option for `network_cli` and `netconf` connection plugin so that the command_timeout can be set per task basis while using `connection=network_cli` or `connection=netconf` eg: ``` - name: run copy command ios_command: commands: - show version vars: ansible_command_timeout: 40 ``` * Modify `ansible-connection` to read command_timeout value from connection plugin options. * Add `ansible_command_timeout` to `persistent_command_timeout` option in `persistent` to support `connection=local` so that it is backward compatibilty * To support `connection=local` pass the timeout value as variables from persistent connection to `ansible-connection` instead of sending it in playcontext * Fix CI failure * Fix review comment
-rwxr-xr-xbin/ansible-connection5
-rw-r--r--lib/ansible/plugins/action/aireos.py3
-rw-r--r--lib/ansible/plugins/action/aruba.py3
-rw-r--r--lib/ansible/plugins/action/asa.py3
-rw-r--r--lib/ansible/plugins/action/bigip.py4
-rw-r--r--lib/ansible/plugins/action/bigiq.py4
-rw-r--r--lib/ansible/plugins/action/ce.py3
-rw-r--r--lib/ansible/plugins/action/cnos.py4
-rw-r--r--lib/ansible/plugins/action/dellos10.py3
-rw-r--r--lib/ansible/plugins/action/dellos6.py3
-rw-r--r--lib/ansible/plugins/action/dellos9.py3
-rw-r--r--lib/ansible/plugins/action/enos.py4
-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/ironware.py3
-rw-r--r--lib/ansible/plugins/action/junos.py5
-rw-r--r--lib/ansible/plugins/action/net_base.py2
-rw-r--r--lib/ansible/plugins/action/nxos.py5
-rw-r--r--lib/ansible/plugins/action/sros.py3
-rw-r--r--lib/ansible/plugins/action/vyos.py5
-rw-r--r--lib/ansible/plugins/connection/netconf.py2
-rw-r--r--lib/ansible/plugins/connection/network_cli.py2
-rw-r--r--lib/ansible/plugins/connection/persistent.py4
-rw-r--r--test/integration/targets/ios_smoke/tests/cli/misc_tests.yaml18
25 files changed, 72 insertions, 34 deletions
diff --git a/bin/ansible-connection b/bin/ansible-connection
index f387199d82..f77e3f2fe6 100755
--- a/bin/ansible-connection
+++ b/bin/ansible-connection
@@ -119,7 +119,7 @@ class ConnectionProcess(object):
if not data:
break
- signal.alarm(self.connection._play_context.timeout)
+ signal.alarm(self.connection.get_option('persistent_command_timeout'))
resp = self.srv.handle_request(data)
signal.alarm(0)
@@ -146,7 +146,7 @@ class ConnectionProcess(object):
self.shutdown()
def command_timeout(self, signum, frame):
- display.display('command timeout triggered, timeout value is %s secs' % self.play_context.timeout, log_only=True)
+ display.display('command timeout triggered, timeout value is %s secs' % self.connection.get_option('persistent_command_timeout'), log_only=True)
self.shutdown()
def handler(self, signum, frame):
@@ -273,6 +273,7 @@ def main():
else:
messages.append('found existing local domain socket, using it!')
conn = Connection(socket_path)
+ conn.set_options(var_options=variables)
pc_data = to_text(init_data)
try:
messages.extend(conn.update_play_context(pc_data))
diff --git a/lib/ansible/plugins/action/aireos.py b/lib/ansible/plugins/action/aireos.py
index 4714cadba5..d9c61242a9 100644
--- a/lib/ansible/plugins/action/aireos.py
+++ b/lib/ansible/plugins/action/aireos.py
@@ -58,10 +58,11 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/aruba.py b/lib/ansible/plugins/action/aruba.py
index 2c2fcc0037..c573938cd2 100644
--- a/lib/ansible/plugins/action/aruba.py
+++ b/lib/ansible/plugins/action/aruba.py
@@ -58,10 +58,11 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/asa.py b/lib/ansible/plugins/action/asa.py
index 40f775a970..e05df8fc9d 100644
--- a/lib/ansible/plugins/action/asa.py
+++ b/lib/ansible/plugins/action/asa.py
@@ -52,13 +52,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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or False
pc.become_pass = provider['auth_pass']
pc.become_method = 'enable'
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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
diff --git a/lib/ansible/plugins/action/bigip.py b/lib/ansible/plugins/action/bigip.py
index 8aecb6231b..967f6074b4 100644
--- a/lib/ansible/plugins/action/bigip.py
+++ b/lib/ansible/plugins/action/bigip.py
@@ -66,10 +66,12 @@ class ActionModule(_ActionModule):
pc.remote_user = provider.get('user', self._play_context.connection_user)
pc.password = provider.get('password', 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': 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/bigiq.py b/lib/ansible/plugins/action/bigiq.py
index b962edaa77..182d917cb2 100644
--- a/lib/ansible/plugins/action/bigiq.py
+++ b/lib/ansible/plugins/action/bigiq.py
@@ -66,10 +66,12 @@ class ActionModule(_ActionModule):
pc.remote_user = provider.get('user', self._play_context.connection_user)
pc.password = provider.get('password', 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': 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/ce.py b/lib/ansible/plugins/action/ce.py
index 5ea86fdfc3..2211083a1a 100644
--- a/lib/ansible/plugins/action/ce.py
+++ b/lib/ansible/plugins/action/ce.py
@@ -60,7 +60,7 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
self._task.args['provider'] = provider.update(
host=pc.remote_addr,
port=pc.port,
@@ -71,6 +71,7 @@ class ActionModule(_ActionModule):
pc.connection = 'netconf'
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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/cnos.py b/lib/ansible/plugins/action/cnos.py
index f49cab5ff2..d2f6a3b0a7 100644
--- a/lib/ansible/plugins/action/cnos.py
+++ b/lib/ansible/plugins/action/cnos.py
@@ -51,13 +51,15 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or True
pc.become_pass = provider['auth_pass']
pc.become_method = 'enable'
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)
+ connection.set_options(direct={'persistent_command_timeout': 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/dellos10.py b/lib/ansible/plugins/action/dellos10.py
index 7a45cf84bd..f3eab92db0 100644
--- a/lib/ansible/plugins/action/dellos10.py
+++ b/lib/ansible/plugins/action/dellos10.py
@@ -60,7 +60,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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -68,6 +68,7 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/dellos6.py b/lib/ansible/plugins/action/dellos6.py
index 2a25494aa2..c505789456 100644
--- a/lib/ansible/plugins/action/dellos6.py
+++ b/lib/ansible/plugins/action/dellos6.py
@@ -60,7 +60,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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -68,6 +68,7 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/dellos9.py b/lib/ansible/plugins/action/dellos9.py
index d7c8156d8c..df13626c75 100644
--- a/lib/ansible/plugins/action/dellos9.py
+++ b/lib/ansible/plugins/action/dellos9.py
@@ -60,7 +60,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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -68,6 +68,7 @@ class ActionModule(_ActionModule):
display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/enos.py b/lib/ansible/plugins/action/enos.py
index 69f256b3c5..1182f57e58 100644
--- a/lib/ansible/plugins/action/enos.py
+++ b/lib/ansible/plugins/action/enos.py
@@ -51,13 +51,15 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or True
pc.become_pass = provider['auth_pass']
pc.become_method = 'enable'
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)
+ connection.set_options(direct={'persistent_command_timeout': 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/eos.py b/lib/ansible/plugins/action/eos.py
index e8d2a44338..0ecfcb7622 100644
--- a/lib/ansible/plugins/action/eos.py
+++ b/lib/ansible/plugins/action/eos.py
@@ -66,7 +66,6 @@ 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']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -75,8 +74,8 @@ 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py
index 6fbe7dba9f..5e531dbf32 100644
--- a/lib/ansible/plugins/action/ios.py
+++ b/lib/ansible/plugins/action/ios.py
@@ -58,7 +58,6 @@ 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']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -67,8 +66,8 @@ 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py
index 8b9e5eae82..2a7b6db3ae 100644
--- a/lib/ansible/plugins/action/iosxr.py
+++ b/lib/ansible/plugins/action/iosxr.py
@@ -61,13 +61,12 @@ 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']) 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/ironware.py b/lib/ansible/plugins/action/ironware.py
index 5033af9436..b6c92aca80 100644
--- a/lib/ansible/plugins/action/ironware.py
+++ b/lib/ansible/plugins/action/ironware.py
@@ -59,7 +59,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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -67,6 +67,7 @@ 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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
diff --git a/lib/ansible/plugins/action/junos.py b/lib/ansible/plugins/action/junos.py
index 147340a008..32bca0f84c 100644
--- a/lib/ansible/plugins/action/junos.py
+++ b/lib/ansible/plugins/action/junos.py
@@ -72,13 +72,12 @@ 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']) 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/net_base.py b/lib/ansible/plugins/action/net_base.py
index cd1c2121af..b4f75b7f42 100644
--- a/lib/ansible/plugins/action/net_base.py
+++ b/lib/ansible/plugins/action/net_base.py
@@ -151,6 +151,8 @@ class ActionModule(ActionBase):
connection = self._shared_loader_obj.connection_loader.get('persistent',
play_context, sys.stdin)
+ connection.set_options(direct={'persistent_command_timeout': play_context.timeout})
+
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, play_context.remote_addr)
if not socket_path:
diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py
index ebb5465e7b..e9230b2590 100644
--- a/lib/ansible/plugins/action/nxos.py
+++ b/lib/ansible/plugins/action/nxos.py
@@ -85,7 +85,6 @@ 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']) if provider['timeout'] else None
pc.become = provider['authorize'] or False
if pc.become:
pc.become_method = 'enable'
@@ -94,8 +93,8 @@ 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/sros.py b/lib/ansible/plugins/action/sros.py
index e4c346329c..5a3cb9a527 100644
--- a/lib/ansible/plugins/action/sros.py
+++ b/lib/ansible/plugins/action/sros.py
@@ -55,10 +55,11 @@ 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)
+ command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
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)
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py
index 383db5ed66..c4d8b3bbe5 100644
--- a/lib/ansible/plugins/action/vyos.py
+++ b/lib/ansible/plugins/action/vyos.py
@@ -58,13 +58,12 @@ 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']) 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')
+ command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
+ connection.set_options(direct={'persistent_command_timeout': command_timeout})
socket_path = connection.run()
display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py
index 17e47fe7ae..08cc17ee0d 100644
--- a/lib/ansible/plugins/connection/netconf.py
+++ b/lib/ansible/plugins/connection/netconf.py
@@ -152,6 +152,8 @@ options:
key: command_timeout
env:
- name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
+ vars:
+ - name: ansible_command_timeout
"""
import os
diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py
index d9689bb30f..40235cc207 100644
--- a/lib/ansible/plugins/connection/network_cli.py
+++ b/lib/ansible/plugins/connection/network_cli.py
@@ -155,6 +155,8 @@ options:
key: command_timeout
env:
- name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
+ vars:
+ - name: ansible_command_timeout
"""
import getpass
diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py
index 8e128c14e1..96cdb988af 100644
--- a/lib/ansible/plugins/connection/persistent.py
+++ b/lib/ansible/plugins/connection/persistent.py
@@ -26,6 +26,8 @@ options:
key: command_timeout
env:
- name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
+ vars:
+ - name: ansible_command_timeout
"""
import os
import pty
@@ -119,7 +121,7 @@ class Connection(ConnectionBase):
stdin.write(src)
stdin.write(b'\n#END_INIT#\n')
- src = cPickle.dumps({}, protocol=0)
+ src = cPickle.dumps({'ansible_command_timeout': self.get_option('persistent_command_timeout')}, protocol=0)
stdin.write(src)
stdin.write(b'\n#END_VARS#\n')
diff --git a/test/integration/targets/ios_smoke/tests/cli/misc_tests.yaml b/test/integration/targets/ios_smoke/tests/cli/misc_tests.yaml
index 7ac78c92bd..e9a116ed0f 100644
--- a/test/integration/targets/ios_smoke/tests/cli/misc_tests.yaml
+++ b/test/integration/targets/ios_smoke/tests/cli/misc_tests.yaml
@@ -19,4 +19,22 @@
provider: "{{ cli }}"
register: result
+- name: run ios commands to test command_timeout
+ ios_command:
+ commands:
+ - show running-config all
+ - show interfaces
+ - show running-config all
+ vars:
+ ansible_command_timeout: 1
+ ignore_errors: True
+ register: result
+ when: ansible_connection == 'network_cli'
+
+- assert:
+ that:
+ - 'result.failed == true'
+ - "'timeout trying to send command' in result.module_stderr"
+ when: ansible_connection == 'network_cli'
+
- debug: msg="END ios_smoke cli/misc_tests.yaml on connection={{ ansible_connection }}"