1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allow timeout to be configurable (#14973)

This commit is contained in:
Patrick Ogenstad 2016-04-14 15:35:07 +02:00 committed by Nathaniel Case
parent 78365e206f
commit 6c5ea685a2
3 changed files with 11 additions and 5 deletions

View file

@ -33,7 +33,8 @@ NET_COMMON_ARGS = dict(
ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
authorize=dict(default=False, fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'), authorize=dict(default=False, fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
auth_pass=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])), auth_pass=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
provider=dict() provider=dict(),
timeout=dict(default=10, type='int')
) )
CLI_PROMPTS_RE = [ CLI_PROMPTS_RE = [
@ -74,11 +75,12 @@ class Cli(object):
username = self.module.params['username'] username = self.module.params['username']
password = self.module.params['password'] password = self.module.params['password']
key_filename = self.module.params['ssh_keyfile'] key_filename = self.module.params['ssh_keyfile']
timeout = self.module.params['timeout']
try: try:
self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE,
errors_re=CLI_ERRORS_RE) errors_re=CLI_ERRORS_RE)
self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename) self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename, timeout=timeout)
except Exception, exc: except Exception, exc:
msg = 'failed to connect to %s:%s - %s' % (host, port, str(exc)) msg = 'failed to connect to %s:%s - %s' % (host, port, str(exc))
self.module.fail_json(msg=msg) self.module.fail_json(msg=msg)
@ -175,4 +177,3 @@ def get_module(**kwargs):
module.fail_json(msg='paramiko is required but does not appear to be installed') module.fail_json(msg='paramiko is required but does not appear to be installed')
return module return module

View file

@ -106,7 +106,7 @@ class Shell(object):
key_filename=key_filename, allow_agent=allow_agent) key_filename=key_filename, allow_agent=allow_agent)
self.shell = self.ssh.invoke_shell() self.shell = self.ssh.invoke_shell()
self.shell.settimeout(10) self.shell.settimeout(timeout)
if self.kickstart: if self.kickstart:
self.shell.sendall("\n") self.shell.sendall("\n")
@ -184,4 +184,3 @@ class Shell(object):
if match: if match:
self._matched_prompt = match.group() self._matched_prompt = match.group()
return True return True

View file

@ -76,6 +76,12 @@ options:
environment variable ANSIBLE_NET_AUTH_PASS will be used instead. environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
required: false required: false
default: none default: none
timeout:
description:
- Specifies idle timeout for the connection. Useful if the console
freezes before continuing. For example when saving configurations.
required: false
default: 10
provider: provider:
description: description:
- Convience method that allows all M(ios) arguments to be passed as - Convience method that allows all M(ios) arguments to be passed as