powershell - 将 ansible 变量传递给包含花括号的 powershell 代码
问题描述
我想将包含 ansible 变量的 powershell 命令的执行与 win_shell 模块集成到 ansible 任务中,否则我总是收到错误“模板错误时模板字符串:预期令牌'打印语句结束',得到'std'”。但是,我尝试添加引号和双引号,但没有任何帮助。这是使用 powershell 代码的任务:
- name: add windows key
win_shell: |
$kms = '{{kms}}'
$OSversion = (Get-WmiObject -class Win32_OperatingSystem).Caption
switch -Regex ($OSversion) {
'Windows Server 2016 Standard' {$key = {{ key1 }};break}
'Windows Server 2016 Datacenter' {$key = {{ key2 }};break}
'Windows Server 2019 Datacenter' {$key = {{ key3 }};break}
}
$KMSservice = Get-WMIObject -query "select * from SoftwareLicensingService"
Write-Debug 'Activating Windows.'
$null = $KMSservice.InstallProductKey($key)
$null = $KMSservice.SetKeyManagementServiceMachine($kms)
$null = $KMSservice.RefreshLicenseStatus()
我对'{{kms}}' var没有任何问题,但只有在powershell花括号之间有ansible vars
ansible 变量 key1/2/3 被设置到一个 var 文件中。
谢谢您的帮助!
解决方案
推荐阅读
- javascript - 使用地图反应 setState 对象数组不起作用?
- laravel - 服务器上的 Laravel 共享太高
- c - 很难理解我们如何在这个给定的任务中 void printSp(int),
- python - Pandas 包含条件返回 True 但希望返回为 1 或 0 - 创建系列/数据框列
- oracle - java中的SQLcl错误:包oracle.jdbc.internal被密封
- php - Trying to echo an image in Php, cant find src
- javascript - 带有 webpack 的 react-redux 给出错误 Uncaught TypeError: Super expression must be null or a function, not undefined
- python - 使用 Pandas 进行基本矩阵计算
- sql - 由任务组成的任务的 ER 模型
- java - java:超出内存限制?