mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Base changes required to allow winrm to work on py3 (#24744)
This commit is contained in:
parent
f217dae938
commit
e7d8ebf080
2 changed files with 12 additions and 6 deletions
|
@ -839,14 +839,14 @@ def modify_module(module_name, module_path, module_args, task_vars=dict(), modul
|
||||||
|
|
||||||
def build_windows_module_payload(module_name, module_path, b_module_data, module_args, task_vars, task, play_context, environment):
|
def build_windows_module_payload(module_name, module_path, b_module_data, module_args, task_vars, task, play_context, environment):
|
||||||
exec_manifest = dict(
|
exec_manifest = dict(
|
||||||
module_entry=base64.b64encode(b_module_data),
|
module_entry=to_text(base64.b64encode(b_module_data)),
|
||||||
powershell_modules=dict(),
|
powershell_modules=dict(),
|
||||||
module_args=module_args,
|
module_args=module_args,
|
||||||
actions=['exec'],
|
actions=['exec'],
|
||||||
environment=environment
|
environment=environment
|
||||||
)
|
)
|
||||||
|
|
||||||
exec_manifest['exec'] = base64.b64encode(to_bytes(leaf_exec))
|
exec_manifest['exec'] = to_text(base64.b64encode(to_bytes(leaf_exec)))
|
||||||
|
|
||||||
if task.async > 0:
|
if task.async > 0:
|
||||||
exec_manifest["actions"].insert(0, 'async_watchdog')
|
exec_manifest["actions"].insert(0, 'async_watchdog')
|
||||||
|
@ -874,8 +874,14 @@ def build_windows_module_payload(module_name, module_path, b_module_data, module
|
||||||
# TODO: add #Requires checks for Ansible.ModuleUtils.X
|
# TODO: add #Requires checks for Ansible.ModuleUtils.X
|
||||||
|
|
||||||
for m in module_names:
|
for m in module_names:
|
||||||
exec_manifest["powershell_modules"][m] = base64.b64encode(
|
m = to_text(m)
|
||||||
to_bytes(_slurp(os.path.join(_MODULE_UTILS_PATH, m + ".ps1"))))
|
exec_manifest["powershell_modules"][m] = to_text(
|
||||||
|
base64.b64encode(
|
||||||
|
to_bytes(
|
||||||
|
_slurp(os.path.join(_MODULE_UTILS_PATH, m + ".ps1"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# FUTURE: smuggle this back as a dict instead of serializing here; the connection plugin may need to modify it
|
# FUTURE: smuggle this back as a dict instead of serializing here; the connection plugin may need to modify it
|
||||||
b_module_data = json.dumps(exec_manifest)
|
b_module_data = json.dumps(exec_manifest)
|
||||||
|
|
|
@ -392,11 +392,11 @@ class Connection(ConnectionBase):
|
||||||
return (result.status_code, result.std_out, result.std_err)
|
return (result.status_code, result.std_out, result.std_err)
|
||||||
|
|
||||||
def is_clixml(self, value):
|
def is_clixml(self, value):
|
||||||
return value.startswith("#< CLIXML")
|
return value.startswith(b"#< CLIXML")
|
||||||
|
|
||||||
# hacky way to get just stdout- not always sure of doc framing here, so use with care
|
# hacky way to get just stdout- not always sure of doc framing here, so use with care
|
||||||
def parse_clixml_stream(self, clixml_doc, stream_name='Error'):
|
def parse_clixml_stream(self, clixml_doc, stream_name='Error'):
|
||||||
clear_xml = clixml_doc.replace('#< CLIXML\r\n', '')
|
clear_xml = clixml_doc.replace(b'#< CLIXML\r\n', b'')
|
||||||
doc = xmltodict.parse(clear_xml)
|
doc = xmltodict.parse(clear_xml)
|
||||||
lines = [l.get('#text', '').replace('_x000D__x000A_', '') for l in doc.get('Objs', {}).get('S', {}) if l.get('@S') == stream_name]
|
lines = [l.get('#text', '').replace('_x000D__x000A_', '') for l in doc.get('Objs', {}).get('S', {}) if l.get('@S') == stream_name]
|
||||||
return '\r\n'.join(lines)
|
return '\r\n'.join(lines)
|
||||||
|
|
Loading…
Reference in a new issue