将参数从外部文件(模板)传递到puppet脚本

时间:2013-11-26 09:27:08

标签: ruby templates puppet

您好我正在尝试使用puppet脚本执行exe文件。我的exe文件接受了3个参数,如param1,param2和param3。我想要的只是通过外部文件传递这些参数。我怎么能这样做?

以下是我的示例代码:

exec { "executing exe file":
  command => 'copyfile.exe "DestinatoinPath" "sourcefilename" "destinationfilename" ',
}  

我想要的只是从外部文件传递所有这些值并在此处使用它。

有人可以帮我解决此问题吗

这是我的踪迹:

这是我的目录结构:

puppet\modules\mymodule\manifests\myfile.pp and 
puppet\modules\mymodule\templates\params.erb 

and my erb file is having a value of path ex: d:\test1.txt e:\test1.txt testfilename 

$myparams = template("mymodule/params.erb") 

exec { "executing exe file":
  command => '$myparams',
} 

1 个答案:

答案 0 :(得分:2)

编辑:

问题的根源是尝试直接调用模块清单,因此模板查找失败。解决方案不是使用模块并指定完整的模板路径。


有两种主要方式:

在范围内声明变量

#acceptable for a throwaway manifest
$path = "DestinationPath"
$source = "sourcefilename"
$destination "destinationfilename"

exec { "executing exe file":
    command => 'copyfile.exe ${path} ${source} ${destination}',
}

将其包装在参数化类/定义类型

# parameterized class, included only once
class executing_exe_file ($path, $source, $destination) {
    exec { "executing exe file":
        command => 'copyfile.exe ${path} ${source} ${destination}',
    }
}

OR

# defined resource, can be repeated multiple times
define executing_exe_file ($path, $source, $destination) {
    exec { "executing exe file":
        command => 'copyfile.exe ${path} ${source} ${destination}',
    }
}

THEN

executing_exe_file { "executing exe file":
    path: "DestinationPath",
    source: "sourcefilename",
    destination: "destinationfilename",
}

另外,作为旁注,您必须确保copyfile.exe完全合格。