在我的木偶脚本中,我有2个执行不同batch file的exec调用
exec { command => 'file1.bat' } exec { command => 'file2.bat' }
如果file1.bat使用SET环境variables
SET VAR1=someVal
它不能从我预期的file2.bat访问。
但是,如果我使用SETX
SETX VAR1 someVal -m
它在file2.bat中仍然不可用。
我已经能够对file2.bat进行variables更改的唯一方法是直接在file1.bat中的registry(使用reg ADD)中设置variables,然后在file2.bat中查询它(使用reg QUERY)。 有一个更好的方法吗?
我无法将file1.bat和file2.bat组合到一个脚本中,因为它们在别处是独立使用的。
在你的木偶清单中设置variables,并从模板文件中获取批处理脚本,其中包含variables,否则将使用OSvariables。
例如,从我的postfix.erb文件中的一行:
myhostname = <%= fqdn %>
有关实际代码的一个很好的资源,请参阅有没有想过如何configuration维基媒体服务器? 。 你可以用git检查仓库。
file { "file1 batch script": path => "/whatever/you/want/file1.bat", content => template("file1.erb"); } -> exec { command = file1.bat } file { "file2 batch script": path => "/whatever/you/want/file2.bat", content => template("file2.erb"); } -> exec { command = file1.bat }
以一些ERB值为例。
任何环境variables都可以通过脚本来读取,就像直接运行一样。 另外,puppet可以设置一个命令的运行环境variables在一个exec块中。 查看Puppettypes引用了解更多信息。
至于将variables导入puppet,请阅读自定义事实 。