saltstack远程操作WINDOWS的POWERSHELL脚本

简介:

这个东东,花了两天来查找资料和测试,终于算是搞定。作记录:

 

直接在MASTER上执行的命令:

salt '*' cmd.script salt://scripts/windows_task.ps1 args=' -Input c:\tmp\infile.txt' shell='powershell'

直接通过SALT-API执行的命令:

curl -k https://127.0.0.1:8000/ -H "Accept: application/x-yaml" -H "X-Auth-Token: 0ef19709d068834637758b1b5a9af6927a7a651d" -d client='local' -d tgt='cnsz121685-10.25.174.81' -d fun='cmd.script' -d arg='salt://tengine_root/autodeploy/opscripts/test/sbp.ps1' -d arg="static ADE 20160127091855DB backup" -d arg='shell=powershell'

通过我们的API传参考:

if server_sys == 'LINUX':
            args = [salt_cmd.strip(), server_type+' '+site_name+' '+app+' '+deploy_version+' '+action, 'runas='+op_name]
        if server_sys == 'WINDOWS':
            args = [salt_cmd.strip(), server_type+' '+site_name+' '+app+' '+deploy_version+' '+action, 'shell=powershell']
        result = saltapi_inst(server_env).cmd_script(tgt, args)

而自制API用了REQUESTS。

复制代码
def cmd_script(self, tgt, arg, expr_form='compound', fun='cmd.script'):
        r = requests.post(self.host, verify=False, cookies=self.cookies, data={'tgt': tgt,
                                                                               'client': 'local',
                                                                               'expr_form': expr_form,
                                                                               'fun': fun,
                                                                               'arg': arg})
        if r.status_code == 200:
            # print r.json()
            return r.json()
        else:
            raise Exception('Error from source %s' % r.text)
复制代码
目录
相关文章
|
5天前
|
Windows
Powershell 重新排列去重 Windows环境变量
【9月更文挑战第13天】本文介绍如何使用PowerShell对Windows环境变量进行重新排列和去重。首先通过`$env:`访问环境变量,接着使用`-split`命令分割路径,再利用`Select-Object -Unique`去除重复项。之后可根据需要对路径进行排序,最后将处理后的路径组合并更新环境变量。注意修改环境变量前应备份重要数据并了解潜在影响。
39 10
|
26天前
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
|
23天前
|
安全 Shell Windows
记windows自定义bat脚本自启动
【8月更文挑战第27天】在Windows系统中,可让自定义bat脚本自启动的方法有两种:一是利用“启动”文件夹,通过创建bat脚本的快捷方式并将其放置于该文件夹;二是使用任务计划程序,创建一个启动时触发的任务来运行bat脚本。需确保脚本正确安全,避免对系统产生不良影响。
|
27天前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
27天前
|
存储 Shell 容器
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
|
27天前
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误
|
27天前
|
Java
【Azure 应用服务】使用PowerShell脚本上传文件至App Service目录  
【Azure 应用服务】使用PowerShell脚本上传文件至App Service目录  
|
28天前
|
Java 开发工具 Windows
【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例
【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例
|
28天前
|
缓存 监控 NoSQL
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
|
28天前
|
存储 数据库
【Azure 应用服务】在Azure Funciton中使用Powershell脚本函数,需要存储一些变量值如何解决?
【Azure 应用服务】在Azure Funciton中使用Powershell脚本函数,需要存储一些变量值如何解决?