From 3620fce071e0993cc795275e09d632db11a44061 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 3 Jun 2019 17:40:58 +0100 Subject: [PATCH] issue #593: expose configurables for SSH keepalive and increase the default --- ansible_mitogen/connection.py | 6 +++++ ansible_mitogen/transport_config.py | 24 +++++++++++++++++++ docs/ansible_detailed.rst | 5 ++++ docs/changelog.rst | 10 ++++++-- .../delegate_to_template.yml | 4 ++++ .../stack_construction.yml | 14 +++++++++++ 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 411b99f1..1b6a2e9a 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -145,6 +145,12 @@ def _connect_ssh(spec): 'ssh_args': spec.ssh_args(), 'ssh_debug_level': spec.mitogen_ssh_debug_level(), 'remote_name': get_remote_name(spec), + 'keepalive_count': ( + spec.mitogen_ssh_keepalive_count() or 10 + ), + 'keepalive_interval': ( + spec.mitogen_ssh_keepalive_interval() or 30 + ), } } diff --git a/ansible_mitogen/transport_config.py b/ansible_mitogen/transport_config.py index 6fcfba04..27e368d4 100644 --- a/ansible_mitogen/transport_config.py +++ b/ansible_mitogen/transport_config.py @@ -276,6 +276,18 @@ class Spec(with_metaclass(abc.ABCMeta, object)): The path to the "machinectl" program for the 'setns' transport. """ + @abc.abstractmethod + def mitogen_ssh_keepalive_interval(self): + """ + The SSH ServerAliveInterval. + """ + + @abc.abstractmethod + def mitogen_ssh_keepalive_count(self): + """ + The SSH ServerAliveCount. + """ + @abc.abstractmethod def mitogen_ssh_debug_level(self): """ @@ -427,6 +439,12 @@ class PlayContextSpec(Spec): def mitogen_lxc_info_path(self): return self._connection.get_task_var('mitogen_lxc_info_path') + def mitogen_ssh_keepalive_interval(self): + return self._connection.get_task_var('mitogen_ssh_keepalive_interval') + + def mitogen_ssh_keepalive_count(self): + return self._connection.get_task_var('mitogen_ssh_keepalive_count') + def mitogen_machinectl_path(self): return self._connection.get_task_var('mitogen_machinectl_path') @@ -644,6 +662,12 @@ class MitogenViaSpec(Spec): def mitogen_lxc_info_path(self): return self._host_vars.get('mitogen_lxc_info_path') + def mitogen_ssh_keepalive_interval(self): + return self._host_vars.get('mitogen_ssh_keepalive_interval') + + def mitogen_ssh_keepalive_count(self): + return self._host_vars.get('mitogen_ssh_keepalive_count') + def mitogen_machinectl_path(self): return self._host_vars.get('mitogen_machinectl_path') diff --git a/docs/ansible_detailed.rst b/docs/ansible_detailed.rst index f709f8f3..e5bd0669 100644 --- a/docs/ansible_detailed.rst +++ b/docs/ansible_detailed.rst @@ -1007,6 +1007,11 @@ except connection delegation is supported. otherwise :data:`False`. This will change to off by default in a future release. If you are targetting many hosts on a fast network, please consider disabling SSH compression. +* ``mitogen_ssh_keepalive_count``: integer count of server keepalive messages to + which no reply is received before considering the SSH server dead. Defaults + to 10. +* ``mitogen_ssh_keepalive_count``: integer seconds delay between keepalive + messages. Defaults to 30. Debugging diff --git a/docs/changelog.rst b/docs/changelog.rst index 1e4c7e18..9f5ed993 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -45,6 +45,11 @@ Fixes :func:`os.getcwd` prior to :class:`AnsibleModule` initialization, such as the Ansible 2.7 ``pip`` module, cannot fail due to the behavior of a prior task. +* `#593 `_: the SSH connection method + exposes ``mitogen_ssh_keepalive_interval`` and + ``mitogen_ssh_keepalive_count`` variables, and the default timeout for an SSH + server has been increased from `15*3` seconds to `30*10` seconds. + Thanks! ~~~~~~~ @@ -53,8 +58,9 @@ Mitogen would not be possible without the support of users. A huge thanks for bug reports, testing, features and fixes in this release contributed by `Anton Markelov `_, `Nigel Metheringham `_, -`Orion Poplawski `_, and -`Ulrich Schreiner `_. +`Orion Poplawski `_, +`Ulrich Schreiner `_, and +`Yuki Nishida `_. v0.2.7 (2019-05-19) diff --git a/tests/ansible/integration/connection_delegation/delegate_to_template.yml b/tests/ansible/integration/connection_delegation/delegate_to_template.yml index d7af7f81..bfde1265 100644 --- a/tests/ansible/integration/connection_delegation/delegate_to_template.yml +++ b/tests/ansible/integration/connection_delegation/delegate_to_template.yml @@ -37,6 +37,8 @@ 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, 'python_path': ["/usr/bin/python"], @@ -65,6 +67,8 @@ 'hostname': 'cd-normal-alias', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, 'python_path': ["/usr/bin/python"], diff --git a/tests/ansible/integration/connection_delegation/stack_construction.yml b/tests/ansible/integration/connection_delegation/stack_construction.yml index 50029569..ed298599 100644 --- a/tests/ansible/integration/connection_delegation/stack_construction.yml +++ b/tests/ansible/integration/connection_delegation/stack_construction.yml @@ -71,6 +71,8 @@ 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -112,6 +114,8 @@ 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -164,6 +168,8 @@ 'hostname': 'cd-normal-normal', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -205,6 +211,8 @@ 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -233,6 +241,8 @@ 'hostname': 'cd-normal-alias', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -285,6 +295,8 @@ 'hostname': 'cd-newuser-normal-normal', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"], @@ -327,6 +339,8 @@ 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, + 'keepalive_interval': 30, + 'keepalive_count': 10, 'password': null, 'port': null, "python_path": ["/usr/bin/python"],