从厨师到Powershell传递变量 [英] Passing variables from chef to powershell
问题描述
我正在使用powershell_script食谱。我想使用的powershell脚本需要命令行输入。有没有办法传递来自Chef的变量并将其传递到Powershell脚本中?
I am using the powershell_script cookbook. The powershell script that I would like to use takes command line inputs. Is there a way to pass variables from chef and pass them into the powershell script?
input1 = "input1"
input2 = "input2"
powershell_script 'example' do
code "...\example.ps1"
end
因此,如果我的example.ps1将input1和input2作为命令行参数,我该如何将它们传递给:
So if my example.ps1 took input1 and input2 as command line arguments how would I pass them into:
代码 ... \example.ps1
推荐答案
powershell_script
资源上的 code
属性采用您要运行的原义PowerShell代码,而不是其路径。无论如何,您都可以通过字符串插值来处理它。例如:
The code
property on the powershell_script
resource takes the literal PowerShell code you want to run, not a path to it. Regardless, you would handle it via string interpolation. For example:
execute "C:/path/to/example.ps1 #{node['foo']} #{node['bar']}"
这篇关于从厨师到Powershell传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!