From ad99d526795e21d8b26af8b70e80b6b83b782de2 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Thu, 15 Dec 2016 15:47:39 -0500 Subject: [PATCH] adds feature to allow connection to set action plugin (#18762) Connection plugin can define default action plugin to use by providing action_handler instance variable. This will override the default action plugin normal --- lib/ansible/executor/task_executor.py | 3 ++- lib/ansible/plugins/connection/network_cli.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 8a3a37e6c8a..7c710e6543b 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -762,7 +762,8 @@ class TaskExecutor: raise AnsibleError("async mode is not supported with the %s module" % self._task.action) handler_name = self._task.action elif self._task.async == 0: - handler_name = 'normal' + pc_conn = self._shared_loader_obj.connection_loader.get(self._play_context.connection, class_only=True) + handler_name = getattr(pc_conn, 'action_handler', 'normal') else: handler_name = 'async' diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index b65c2ba7b6a..6cec05a510b 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -30,12 +30,19 @@ from ansible.plugins import terminal_loader from ansible.plugins.connection import ensure_connect from ansible.plugins.connection.paramiko_ssh import Connection as _Connection +try: + from __main__ import display +except ImportError: + from ansible.utils.display import Display + display = Display() + class Connection(_Connection): ''' CLI (shell) SSH connections on Paramiko ''' transport = 'network_cli' has_pipelining = False + action_handler = 'network' def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) @@ -97,6 +104,7 @@ class Connection(_Connection): self._terminal.on_authorize(passwd=auth_pass) def close(self): + display.vvv('closing connection', host=self._play_context.remote_addr) self.close_shell() super(Connection, self).close()