diff --git a/apps/assets/models/asset.py b/apps/assets/models/asset.py index 08a44e93c..70e2abb2a 100644 --- a/apps/assets/models/asset.py +++ b/apps/assets/models/asset.py @@ -155,6 +155,12 @@ class Platform(models.Model): ) return linux.id + def is_windows(self): + return self.base.lower() in ('windows',) + + def is_unixlike(self): + return self.base.lower() in ("linux", "unix", "macos", "bsd") + def __str__(self): return self.name @@ -233,22 +239,19 @@ class Asset(ProtocolsMixin, NodesRelationMixin, OrgModelMixin): return False, warning return True, warning - def is_windows(self): - return self.platform_base == "Windows" - - def is_unixlike(self): - if self.platform_base not in ("Windows", "Windows2016", "Other"): - return True - else: - return False - - def is_support_ansible(self): - return self.has_protocol('ssh') and self.platform_base not in ("Other",) - @lazyproperty def platform_base(self): return self.platform.base + def is_windows(self): + return self.platform.is_windows() + + def is_unixlike(self): + return self.platform.is_unixlike() + + def is_support_ansible(self): + return self.has_protocol('ssh') and self.platform_base not in ("Other",) + @property def cpu_info(self): info = "" diff --git a/apps/ops/ansible/runner.py b/apps/ops/ansible/runner.py index 5f25ee2c4..b6c6b8ee1 100644 --- a/apps/ops/ansible/runner.py +++ b/apps/ops/ansible/runner.py @@ -228,7 +228,7 @@ class AdHocRunner: class CommandRunner(AdHocRunner): results_callback_class = CommandResultCallback - modules_choices = ('shell', 'raw', 'command', 'script') + modules_choices = ('shell', 'raw', 'command', 'script', 'win_shell') def execute(self, cmd, pattern, module='shell'): if module and module not in self.modules_choices: diff --git a/apps/ops/models/command.py b/apps/ops/models/command.py index 3df42d5bc..13e3c1714 100644 --- a/apps/ops/models/command.py +++ b/apps/ops/models/command.py @@ -63,7 +63,12 @@ class CommandExecution(models.Model): if ok: runner = CommandRunner(self.inventory) try: - result = runner.execute(self.command, 'all') + host = self.hosts[0] + if host.is_windows(): + shell = 'win_shell' + else: + shell = 'shell' + result = runner.execute(self.command, 'all', module=shell) self.result = result.results_command except SoftTimeLimitExceeded as e: print("Run timeout than 60s")