mirror of
https://github.com/ansible/ansible.git
synced 2026-07-28 16:15:12 +02:00
* Add support for PowerShell modules on POSIX Adds support for running modules written in PowerShell on non-Windows hosts. This includes references to a PowerShell or C# module_util located in Ansible or a collection. Not all module utils will work outside of Windows but `Ansible.Basic` will do so. Support for PowerShell modules on non-Windows is up to the module and collection author. This PR just enables the ability to run them through the existing PowerShell execution wrapper. * Fix up sanity and unit tests, try and run in separate CI group * Fix up powershell.sh group detection * More sanity fixes * More sanity fixes * Ensure shebang is part of command to run * Try and simplify exec module logic * Attempt to get powershell group running in CI * Fix up test integration aliases for powershell * Remove ansible.windows collection for integration support * Revert the win_powershell changes now they aren't needed * Simplify test matrix and use default container
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
# Copyright (c) 2017 Ansible Project
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
from __future__ import annotations
|
|
|
|
|
|
import os
|
|
import json
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
|
|
from ansible.modules import async_wrapper
|
|
|
|
|
|
class TestAsyncWrapper:
|
|
|
|
def test_run_module(self, monkeypatch):
|
|
|
|
module_result = {'rc': 0}
|
|
module_lines = [
|
|
'import sys',
|
|
'sys.stderr.write("stderr stuff")',
|
|
"print('%s')" % json.dumps(module_result)
|
|
]
|
|
module_data = '\n'.join(module_lines) + '\n'
|
|
module_data = module_data.encode('utf-8')
|
|
|
|
workdir = tempfile.mkdtemp()
|
|
fh, fn = tempfile.mkstemp(dir=workdir)
|
|
|
|
with open(fn, 'wb') as f:
|
|
f.write(module_data)
|
|
|
|
command = fn
|
|
jobid = 0
|
|
job_path = os.path.join(os.path.dirname(command), 'job')
|
|
|
|
monkeypatch.setattr(async_wrapper, 'job_path', job_path)
|
|
|
|
res = async_wrapper._run_module(jobid, sys.executable, command)
|
|
|
|
with open(os.path.join(workdir, 'job'), 'r') as f:
|
|
jres = json.loads(f.read())
|
|
|
|
shutil.rmtree(workdir)
|
|
|
|
assert jres.get('rc') == 0
|
|
assert jres.get('stderr') == 'stderr stuff'
|