mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 23:31:25 -07:00
add support for opening shell on remote Windows host (#43919)
* add support for opening shell on remote Windows host * added arg completion and fix sanity check * remove uneeded arg
This commit is contained in:
parent
aef16ee195
commit
6ca4ea0c1f
3 changed files with 79 additions and 20 deletions
|
@ -32,6 +32,22 @@ class ManageWindowsCI(object):
|
|||
:type core_ci: AnsibleCoreCI
|
||||
"""
|
||||
self.core_ci = core_ci
|
||||
self.ssh_args = ['-i', self.core_ci.ssh_key.key]
|
||||
|
||||
ssh_options = dict(
|
||||
BatchMode='yes',
|
||||
StrictHostKeyChecking='no',
|
||||
UserKnownHostsFile='/dev/null',
|
||||
ServerAliveInterval=15,
|
||||
ServerAliveCountMax=4,
|
||||
)
|
||||
|
||||
for ssh_option in sorted(ssh_options):
|
||||
self.ssh_args += ['-o', '%s=%s' % (ssh_option, ssh_options[ssh_option])]
|
||||
|
||||
def setup(self):
|
||||
"""Used in delegate_remote to setup the host, no action is required for Windows."""
|
||||
pass
|
||||
|
||||
def wait(self):
|
||||
"""Wait for instance to respond to ansible ping."""
|
||||
|
@ -59,6 +75,24 @@ class ManageWindowsCI(object):
|
|||
raise ApplicationError('Timeout waiting for %s/%s instance %s.' %
|
||||
(self.core_ci.platform, self.core_ci.version, self.core_ci.instance_id))
|
||||
|
||||
def ssh(self, command, options=None):
|
||||
"""
|
||||
:type command: str | list[str]
|
||||
:type options: list[str] | None
|
||||
"""
|
||||
if not options:
|
||||
options = []
|
||||
|
||||
if isinstance(command, list):
|
||||
command = ' '.join(pipes.quote(c) for c in command)
|
||||
|
||||
run_command(self.core_ci.args,
|
||||
['ssh', '-tt', '-q'] + self.ssh_args +
|
||||
options +
|
||||
['-p', '22',
|
||||
'%s@%s' % (self.core_ci.connection.username, self.core_ci.connection.hostname)] +
|
||||
[command])
|
||||
|
||||
|
||||
class ManageNetworkCI(object):
|
||||
"""Manage access to a network instance provided by Ansible Core CI."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue