execute a script on the minion then delete
(self, script, extension="py", pre_dir="", script_args=None)
| 1992 | return cmd |
| 1993 | |
| 1994 | def execute_script(self, script, extension="py", pre_dir="", script_args=None): |
| 1995 | """ |
| 1996 | execute a script on the minion then delete |
| 1997 | """ |
| 1998 | args = "" |
| 1999 | if script_args: |
| 2000 | if not isinstance(script_args, (list, tuple)): |
| 2001 | script_args = shlex.split(str(script_args)) |
| 2002 | args = " {}".format(" ".join([shlex.quote(str(el)) for el in script_args])) |
| 2003 | if extension == "ps1": |
| 2004 | ret = self.shell.exec_cmd(f'"powershell {script}"') |
| 2005 | else: |
| 2006 | if not self.winrm: |
| 2007 | ret = self.shell.exec_cmd(f"/bin/sh '{pre_dir}{script}'{args}") |
| 2008 | else: |
| 2009 | ret = saltwinshell.call_python(self, script) |
| 2010 | |
| 2011 | # Remove file from target system |
| 2012 | if not self.winrm: |
| 2013 | self.shell.exec_cmd(f"rm '{pre_dir}{script}'") |
| 2014 | else: |
| 2015 | self.shell.exec_cmd(f"del {script}") |
| 2016 | |
| 2017 | return ret |
| 2018 | |
| 2019 | def shim_cmd(self, cmd_str, extension="py"): |
| 2020 | """ |