ansible: Ansible 2.4 compatibility.

wip-fakessh-exit-status
David Wilson 7 years ago
parent a817f5e9e8
commit 1e9fd63343

@ -34,6 +34,11 @@ import ansible
import ansible.plugins
import ansible.plugins.action
try:
from ansible.plugins.loader import module_loader
except ImportError: # Ansible<2.4
from ansible.plugins import module_loader
import mitogen.core
import mitogen.master
from mitogen.utils import cast
@ -52,7 +57,7 @@ def get_command_module_name(module_name):
:return:
"ansible.modules.commands.shell"
"""
path = ansible.plugins.module_loader.find_plugin(module_name, '')
path = module_loader.find_plugin(module_name, '')
relpath = os.path.relpath(path, os.path.dirname(ansible.__file__))
root, _ = os.path.splitext(relpath)
return 'ansible.' + root.replace('/', '.')

@ -37,9 +37,15 @@ import mitogen.utils
import ansible.errors
import ansible.plugins.strategy.linear
import ansible.plugins
import ansible_mitogen.mixins
try:
from ansible.plugins.loader import action_loader
from ansible.plugins.loader import connection_loader
except ImportError: # Ansible <2.4
from ansible.plugins import action_loader
from ansible.plugins import connection_loader
def wrap_action_loader__get(name, *args, **kwargs):
"""
@ -217,19 +223,19 @@ class StrategyModule(ansible.plugins.strategy.linear.StrategyModule):
with references to the real functions.
"""
global action_loader__get
action_loader__get = ansible.plugins.action_loader.get
ansible.plugins.action_loader.get = wrap_action_loader__get
action_loader__get = action_loader.get
action_loader.get = wrap_action_loader__get
global connection_loader__get
connection_loader__get = ansible.plugins.connection_loader.get
ansible.plugins.connection_loader.get = wrap_connection_loader__get
connection_loader__get = connection_loader.get
connection_loader.get = wrap_connection_loader__get
def _remove_wrappers(self):
"""
Uninstall the PluginLoader monkey patches.
"""
ansible.plugins.action_loader.get = action_loader__get
ansible.plugins.connection_loader.get = connection_loader__get
action_loader.get = action_loader__get
connection_loader.get = connection_loader__get
def _add_connection_plugin_path(self):
"""
@ -239,7 +245,7 @@ class StrategyModule(ansible.plugins.strategy.linear.StrategyModule):
# ansible_mitogen base directory:
basedir = os.path.dirname(os.path.dirname(__file__))
conn_dir = os.path.join(basedir, 'connection')
ansible.plugins.connection_loader.add_directory(conn_dir)
connection_loader.add_directory(conn_dir)
def run(self, iterator, play_context, result=0):
self._add_connection_plugin_path()

Loading…
Cancel
Save