From 198cffcb52adc9d61918b63d71a8cdc1ef6aec38 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Mon, 28 Sep 2020 01:32:04 -0400 Subject: [PATCH] Fix passing the connection timeout to connection plugins (#71722) (#71785) (cherry picked from commit 70485421998463036c93ce927b3029fd0e7d4301) --- .../fragments/71722-fix-default-connection-timeout.yaml | 2 ++ docs/docsite/rst/dev_guide/developing_plugins.rst | 2 ++ lib/ansible/executor/task_executor.py | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/71722-fix-default-connection-timeout.yaml diff --git a/changelogs/fragments/71722-fix-default-connection-timeout.yaml b/changelogs/fragments/71722-fix-default-connection-timeout.yaml new file mode 100644 index 00000000000..d3df854e525 --- /dev/null +++ b/changelogs/fragments/71722-fix-default-connection-timeout.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Pass the connection's timeout to connection plugins instead of the task's timeout. diff --git a/docs/docsite/rst/dev_guide/developing_plugins.rst b/docs/docsite/rst/dev_guide/developing_plugins.rst index 2a672848fb6..4ec085059ea 100644 --- a/docs/docsite/rst/dev_guide/developing_plugins.rst +++ b/docs/docsite/rst/dev_guide/developing_plugins.rst @@ -288,6 +288,8 @@ Ansible version 2.1 introduced the ``smart`` connection plugin. The ``smart`` co To create a new connection plugin (for example, to support SNMP, Message bus, or other transports), copy the format of one of the existing connection plugins and drop it into ``connection`` directory on your :ref:`local plugin path `. +Connection plugins can support common options (such as the ``--timeout`` flag) by defining an entry in the documentation for the attribute name (in this case ``timeout``). If the common option has a non-null default, the plugin should define the same default since a different default would be ignored. + For example connection plugins, see the source code for the `connection plugins included with Ansible Core `_. .. _developing_filter_plugins: diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index a0f8d212495..c4bc7886ff6 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -1014,6 +1014,10 @@ class TaskExecutor: task_keys = self._task.dump_attrs() + # The task_keys 'timeout' attr is the task's timeout, not the connection timeout. + # The connection timeout is threaded through the play_context for now. + task_keys['timeout'] = self._play_context.timeout + if self._play_context.password: # The connection password is threaded through the play_context for # now. This is something we ultimately want to avoid, but the first