mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
V2 fixes
* PluginLoader class will now be more selective about loading some plugin classes, if a required base class is specified (used to avoid loading v1 plugins that have changed significantly in their apis) * Added ability for the connection info class to read values from a given hosts variables, to support "magic" variables * Added some more magic variables to the VariableManager output * Fixed a bug in the ActionBase class, where the module configuration code was not correctly handling unicode
This commit is contained in:
parent
f141ec9671
commit
daf533c80e
5 changed files with 75 additions and 36 deletions
|
@ -34,6 +34,7 @@ from ansible.parsing.utils.jsonify import jsonify
|
|||
from ansible.plugins import shell_loader
|
||||
|
||||
from ansible.utils.debug import debug
|
||||
from ansible.utils.unicode import to_bytes
|
||||
|
||||
class ActionBase:
|
||||
|
||||
|
@ -51,21 +52,21 @@ class ActionBase:
|
|||
self._loader = loader
|
||||
self._templar = templar
|
||||
self._shared_loader_obj = shared_loader_obj
|
||||
self._shell = self.get_shell()
|
||||
|
||||
# load the shell plugin for this action/connection
|
||||
if self._connection_info.shell:
|
||||
shell_type = self._connection_info.shell
|
||||
elif hasattr(connection, '_shell'):
|
||||
shell_type = getattr(connection, '_shell')
|
||||
else:
|
||||
shell_type = os.path.basename(C.DEFAULT_EXECUTABLE)
|
||||
|
||||
self._shell = shell_loader.get(shell_type)
|
||||
if not self._shell:
|
||||
raise AnsibleError("Invalid shell type specified (%s), or the plugin for that shell type is missing." % shell_type)
|
||||
|
||||
self._supports_check_mode = True
|
||||
|
||||
def get_shell(self):
|
||||
|
||||
if hasattr(self._connection, '_shell'):
|
||||
shell_plugin = getattr(self._connection, '_shell', '')
|
||||
else:
|
||||
shell_plugin = shell_loader.get(os.path.basename(C.DEFAULT_EXECUTABLE))
|
||||
if shell_plugin is None:
|
||||
shell_plugin = shell_loader.get('sh')
|
||||
|
||||
return shell_plugin
|
||||
|
||||
def _configure_module(self, module_name, module_args):
|
||||
'''
|
||||
Handles the loading and templating of the module code through the
|
||||
|
@ -201,18 +202,13 @@ class ActionBase:
|
|||
Copies the module data out to the temporary module path.
|
||||
'''
|
||||
|
||||
if type(data) == dict:
|
||||
if isinstance(data, dict):
|
||||
data = jsonify(data)
|
||||
|
||||
afd, afile = tempfile.mkstemp()
|
||||
afo = os.fdopen(afd, 'w')
|
||||
try:
|
||||
# FIXME: is this still necessary?
|
||||
#if not isinstance(data, unicode):
|
||||
# #ensure the data is valid UTF-8
|
||||
# data = data.decode('utf-8')
|
||||
#else:
|
||||
# data = data.encode('utf-8')
|
||||
data = to_bytes(data, errors='strict')
|
||||
afo.write(data)
|
||||
except Exception as e:
|
||||
#raise AnsibleError("failure encoding into utf-8: %s" % str(e))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue