-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional ansible-connection execute_module verb #154
Comments
ansible-connection
execute_module
verb
I've had doubts overnight whether this should be the first step -- it may make sense to work from the other direction, first landing an SSH-like connection method only, then extending it with the module executor parts, as it (seemingly) requires less structural change and 'forces' the Mitogen-specific pieces out into the open. Coming from the other direction, we're forced to address the issue of a varying per-task ansible_python_interpreter variable that somehow needs to make it into -connection. Is it okay to discuss it here, or put an item on the agenda for the next meeting? It is still possible to work from this direction, there is no lost work, but I suspect this per-task variables issue might be trickier business that it would be better to get out of the way upfront. |
@dw Maybe put it on the agenda so that it can be discussed with core developers? |
Some thoughts i had while away:
|
Re: |
Just making a note here that ansible-connection lifetime does not match that of existing connection multiplexer -- ansible-connections are torn down in StrategyBase.cleanup() at the end of each play. Mitogen mux exists for the duration of the run |
[WIP! But it's fleshed out enough that good feedback may already be possible. This could be further split into multiple proposals? Or just one cohesive proposal split out into multiple PRs? It may also not include every detail from the meeting yet, or include too much]
Proposal: Optional
ansible-connection
execute_module
verbAuthor: David Wilson <@dw>
Date: 2019-02-06
Motivation
An extension to Ansible delivered as part of the Mitogen project demonstrated through changes to networking and the process model on targets, it is possible to recover significant speed improvements in a variety of real-world scenarios.
In order to achieve its goals, that project rewrote significant portions of the existing module executor in order to integrate with the newly available networking APIs, and to add the ability cache module source code ephemerally for the duration of a playbook run, yielding a large reduction in bandwidth consumption.
Problems
While the long term goal should probably be to merge away the duplicate module executor, as an initial step towards upstreaming it is desirable to reuse the implementation that has already been designed for this new scenario.
Simultaneous to the needs of the Mitogen project, Ansible already supports diverse target environments, where the existing executor has required heavy special casing for use on Windows, or in the case of networking, only sees vestigial use targeting the local machine, as the majority of networking functionality is implemented in terms of action modules. It is therefore desirable to provide a general mechanism to allow selection of the executor.
Solution proposal
This proposal covers a series of hopefully small pull requests, that pave the way for:
postprocess_response()
method out of_execute_module()
,ActionBase
to describe the active configuration leading to a module invocation,ActionBase.execute_module()
function.ConnectionBase
class with documentation of the new method.ansible-connection
program to be extended to support new execute module and file transfer commands, andpersistent
connection plug-in to be extended if necessary to drive selection of the actual connection plug-in that is loaded byansible-connection
.Refactor
postprocess_response()
To emulate the existing executor, the Mitogen
ActionModule
mix-in presently cut-pastes a large chunk of code from the bottom ofexecute_module()
, responsible for normalizingstdout_lines
and similar response fields.This behaviour is an integral part of module response formatting, rather than a feature of the Ansiballz executor, and should therefore be separated from it.
Module invocation type
Since module execution will become a public part of the Connection API and must remain stable over time, it is desirable to introduce a compound type to describe interface parameters, that can be extended without changing the prototype of API methods over time, instead permitting old plug-ins to continue operating even though the compound type has grown new attributes they do not understand.
The alternative of passing parameter lists permits no future backwards-compatible extension of the interface, since it is not possible to know which style of parameter list any particular
Connection.execute_module()
implementation understands.The minimum necessary information to execute a module includes:
module_name
: the module name (command
)module_args
: the final set of template-expanded, processed arguments ({"_raw_params": "hostname"}
)module_env
: the final set of template-expanded, processed module environment variableswrap_async
:True
if the invocation is to start an asynchronous tasktimeout_secs
: If >0, the limit in seconds awrap_async
may execute forAdditional information, such as the currently active
PluginLoader
search paths, are available globally and do not need to be passed to the connection plug-in.The Mitogen extension has a closely related type which includes some attributes that are definitely unneeded for a generic implementation, but exists for the same reason: to delineate an interface
boundary.
TBD that type presently includes access to a
Templar
andtask_vars
to permit templating ofansible_*_interpreter
variables. It is unclear whether a generic interface should include either of these attributes, and if they should not be included, what a replacement should look like.ActionBase
short-circuitThe intention of the
ActionBase
modification is to have a redirect similar to the following:This avoids assuming that all connection plug-ins would feature an
execute_module()
method, which may be true for custom plug-ins that may not inherit fromConnectionBase
.Update
ConnectionBase
ConnectionBase
is updated with a new documentary stub method similar to:Update
ansible-connection
The
ansible-connection
program implements a JSON-RPC server over a UNIX socket. Presently it has no support forexecute_module()
or file transfer.A new
execute_module
JSON-RPC method will be added, implemented by a new forwarder function in (AFAIK)lib/ansible/module_utils/connection.py
New functions will be added in a separate PR to add forwarders for file transfer functionality.
Update
persistent
TBD.
Dependencies (optional)
The changes described may need to occur in set order.
Testing (optional)
Tests to ensure that:
ActionBase
triggers an alternative module executor where the active connection plug-in supplies one.ActionBase
uses Ansiballz given a plug-in entirely missing theexecute_module()
method.ActionBase
yields aModuleInvocation
instance containing the correct information.ActionBase._execute_module
correctly post-processes responses that require it.persistent
+ansible-connection
forwarders correctly implementfetch_file()
persistent
+ansible-connection
forwarders correctly implementput_file()
persistent
+ansible-connection
forwarders correctly implementexecute_module()
TBD:
persistent
correctly determines hosted plug-in does/does not supportexecute_module()
.Documentation (optional)
Relevant docstrings should suffice.
Anything else?
This proposal is currently missing:
a mechanism to avoid any round-trip from the
persistent
plug-in toansible-connection
in order to determine if file transfer orexecute_module()
are supported. It may not be needed, simply turn therelevant JSON-RPC error into
NotImplementedError
or similar.a mechanism to select the actual connection plug-in hosted by
ansible-connection
. It looks like it may be hard-wired forssh
/paramiko
at present?
The text was updated successfully, but these errors were encountered: