@@ -34,6 +34,7 @@ def remote_run(self_module, i):
3434 remote_host = i .get ('remote_host' , 'localhost' )
3535 remote_port = i .get ('remote_port' , '22' )
3636 remote_action = i .get ('remote_action' , 'run' )
37+ remote_shell = i .get ('remote_shell' , '' )
3738
3839 prune_result = prune_input (
3940 {'input' : i , 'extra_keys_starts_with' : ['remote_' ]})
@@ -191,6 +192,15 @@ def remote_run(self_module, i):
191192 if skip_ssh_key_file :
192193 remote_inputs ['skip_ssh_key_file' ] = skip_ssh_key_file
193194
195+ # If a remote shell is specified, wrap all commands to execute inside it
196+ if remote_shell :
197+ all_cmds = remote_pre_run_cmds + run_cmds + remote_post_run_cmds
198+ combined = " ; " .join (all_cmds )
199+ escaped = combined .replace ('\\ ' , '\\ \\ ' ).replace ('"' , '\\ "' )
200+ run_cmds = [f'{ remote_shell } -c "{ escaped } "' ]
201+ remote_pre_run_cmds = []
202+ remote_post_run_cmds = []
203+
194204 # Execute the remote command
195205 mlc_remote_input = {
196206 'action' : 'run' , 'target' : 'script' , 'tags' : 'remote,run,cmds,ssh' ,
@@ -253,6 +263,7 @@ def regenerate_script_cmd(i):
253263 remote_run_settings = i .get ('remote_run_settings' , {})
254264 fake_run = i .get ('fake_run' , False )
255265 remote_action = i .get ('remote_action' , 'run' )
266+ remote_shell = i .get ('remote_shell' , '' )
256267
257268 i_run_cmd = i ['run_cmd' ]
258269
0 commit comments