|
|
@ -34,8 +34,9 @@ files/modules known missing.
|
|
|
|
[0] "Ansible Module Architecture", developing_program_flow_modules.html
|
|
|
|
[0] "Ansible Module Architecture", developing_program_flow_modules.html
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
@ -43,11 +44,10 @@ import os
|
|
|
|
import random
|
|
|
|
import random
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.executor import module_common
|
|
|
|
import ansible.collections.list
|
|
|
|
from ansible.collections.list import list_collection_dirs
|
|
|
|
|
|
|
|
import ansible.errors
|
|
|
|
import ansible.errors
|
|
|
|
import ansible.module_utils
|
|
|
|
import ansible.executor.module_common
|
|
|
|
import ansible.release
|
|
|
|
|
|
|
|
import mitogen.core
|
|
|
|
import mitogen.core
|
|
|
|
import mitogen.select
|
|
|
|
import mitogen.select
|
|
|
|
|
|
|
|
|
|
|
@ -192,7 +192,7 @@ class BinaryPlanner(Planner):
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def detect(cls, path, source):
|
|
|
|
def detect(cls, path, source):
|
|
|
|
return module_common._is_binary(source)
|
|
|
|
return ansible.executor.module_common._is_binary(source)
|
|
|
|
|
|
|
|
|
|
|
|
def get_push_files(self):
|
|
|
|
def get_push_files(self):
|
|
|
|
return [mitogen.core.to_text(self._inv.module_path)]
|
|
|
|
return [mitogen.core.to_text(self._inv.module_path)]
|
|
|
@ -269,7 +269,7 @@ class JsonArgsPlanner(ScriptPlanner):
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def detect(cls, path, source):
|
|
|
|
def detect(cls, path, source):
|
|
|
|
return module_common.REPLACER_JSONARGS in source
|
|
|
|
return ansible.executor.module_common.REPLACER_JSONARGS in source
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WantJsonPlanner(ScriptPlanner):
|
|
|
|
class WantJsonPlanner(ScriptPlanner):
|
|
|
@ -298,11 +298,11 @@ class NewStylePlanner(ScriptPlanner):
|
|
|
|
preprocessing the module.
|
|
|
|
preprocessing the module.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
runner_name = 'NewStyleRunner'
|
|
|
|
runner_name = 'NewStyleRunner'
|
|
|
|
MARKER = re.compile(b'from ansible(?:_collections|\.module_utils)\.')
|
|
|
|
MARKER = re.compile(br'from ansible(?:_collections|\.module_utils)\.')
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def detect(cls, path, source):
|
|
|
|
def detect(cls, path, source):
|
|
|
|
return cls.MARKER.search(source) != None
|
|
|
|
return cls.MARKER.search(source) is not None
|
|
|
|
|
|
|
|
|
|
|
|
def _get_interpreter(self):
|
|
|
|
def _get_interpreter(self):
|
|
|
|
return None, None
|
|
|
|
return None, None
|
|
|
@ -362,7 +362,7 @@ class NewStylePlanner(ScriptPlanner):
|
|
|
|
module_name='ansible_module_%s' % (self._inv.module_name,),
|
|
|
|
module_name='ansible_module_%s' % (self._inv.module_name,),
|
|
|
|
module_path=self._inv.module_path,
|
|
|
|
module_path=self._inv.module_path,
|
|
|
|
search_path=self.get_search_path(),
|
|
|
|
search_path=self.get_search_path(),
|
|
|
|
builtin_path=module_common._MODULE_UTILS_PATH,
|
|
|
|
builtin_path=ansible.executor.module_common._MODULE_UTILS_PATH,
|
|
|
|
context=self._inv.connection.context,
|
|
|
|
context=self._inv.connection.context,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return self._module_map
|
|
|
|
return self._module_map
|
|
|
@ -405,7 +405,7 @@ class ReplacerPlanner(NewStylePlanner):
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def detect(cls, path, source):
|
|
|
|
def detect(cls, path, source):
|
|
|
|
return module_common.REPLACER in source
|
|
|
|
return ansible.executor.module_common.REPLACER in source
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OldStylePlanner(ScriptPlanner):
|
|
|
|
class OldStylePlanner(ScriptPlanner):
|
|
|
@ -427,12 +427,6 @@ _planners = [
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
_get_ansible_module_fqn = module_common._get_ansible_module_fqn
|
|
|
|
|
|
|
|
except AttributeError:
|
|
|
|
|
|
|
|
_get_ansible_module_fqn = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def py_modname_from_path(name, path):
|
|
|
|
def py_modname_from_path(name, path):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Fetch the logical name of a new-style module as it might appear in
|
|
|
|
Fetch the logical name of a new-style module as it might appear in
|
|
|
@ -442,11 +436,12 @@ def py_modname_from_path(name, path):
|
|
|
|
package hierarchy approximated on the target, enabling relative imports
|
|
|
|
package hierarchy approximated on the target, enabling relative imports
|
|
|
|
to function correctly. For example, "ansible.modules.system.setup".
|
|
|
|
to function correctly. For example, "ansible.modules.system.setup".
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if _get_ansible_module_fqn:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return ansible.executor.module_common._get_ansible_module_fqn(path)
|
|
|
|
return _get_ansible_module_fqn(path)
|
|
|
|
except AttributeError:
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
return 'ansible.modules.' + name
|
|
|
|
return 'ansible.modules.' + name
|
|
|
|
|
|
|
|
|
|
|
@ -528,12 +523,15 @@ def _invoke_isolated_task(invocation, planner):
|
|
|
|
context.shutdown()
|
|
|
|
context.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_planner(name, path, source):
|
|
|
|
def _get_planner(invocation, source):
|
|
|
|
for klass in _planners:
|
|
|
|
for klass in _planners:
|
|
|
|
if klass.detect(path, source):
|
|
|
|
if klass.detect(invocation.module_path, source):
|
|
|
|
LOG.debug('%r accepted %r (filename %r)', klass, name, path)
|
|
|
|
LOG.debug(
|
|
|
|
|
|
|
|
'%r accepted %r (filename %r)',
|
|
|
|
|
|
|
|
klass, invocation.module_name, invocation.module_path,
|
|
|
|
|
|
|
|
)
|
|
|
|
return klass
|
|
|
|
return klass
|
|
|
|
LOG.debug('%r rejected %r', klass, name)
|
|
|
|
LOG.debug('%r rejected %r', klass, invocation.module_name)
|
|
|
|
raise ansible.errors.AnsibleError(NO_METHOD_MSG + repr(invocation))
|
|
|
|
raise ansible.errors.AnsibleError(NO_METHOD_MSG + repr(invocation))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -564,7 +562,7 @@ def _load_collections(invocation):
|
|
|
|
Goes through all collection path possibilities and stores paths to installed collections
|
|
|
|
Goes through all collection path possibilities and stores paths to installed collections
|
|
|
|
Stores them on the current invocation to later be passed to the master service
|
|
|
|
Stores them on the current invocation to later be passed to the master service
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
for collection_path in list_collection_dirs():
|
|
|
|
for collection_path in ansible.collections.list.list_collection_dirs():
|
|
|
|
invocation._extra_sys_paths.add(collection_path.decode('utf-8'))
|
|
|
|
invocation._extra_sys_paths.add(collection_path.decode('utf-8'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -596,8 +594,7 @@ def invoke(invocation):
|
|
|
|
module_source = invocation.get_module_source()
|
|
|
|
module_source = invocation.get_module_source()
|
|
|
|
_fix_py35(invocation, module_source)
|
|
|
|
_fix_py35(invocation, module_source)
|
|
|
|
_planner_by_path[invocation.module_path] = _get_planner(
|
|
|
|
_planner_by_path[invocation.module_path] = _get_planner(
|
|
|
|
invocation.module_name,
|
|
|
|
invocation,
|
|
|
|
invocation.module_path,
|
|
|
|
|
|
|
|
module_source
|
|
|
|
module_source
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|