我不确定我是否遵循用例,但你可能会使用它
inline_epp
要么
inline_template
使它看起来像这个功能存在。
例如:
# In real usage this would be the result of a hiera lookup
$simple_lookup_result = ‘9 % 7’
$simple_evaluated = inline_template(“<%= ${simple_lookup_result} %>”)
exec { ‘simple’:
command => “/bin/echo $simple_evaluated”,
logoutput => true,
}
Again, hiera…
$complex_lookup_result = ‘sprintf(“The value is %i”, 9 % 7)’
$complex_evaluated = inline_template(“<%= ${complex_lookup_result} %>”)
exec { ‘complex’:
command => “/bin/echo $complex_evaluated”,
logoutput => true,
}
</code>
结果如下:
$ puppet apply eval.pp
Notice: Compiled catalog for box in environment production in 0.06 seconds
Notice: /Stage[main]/Main/Exec[simple]/returns: 2
Notice: /Stage[main]/Main/Exec[simple]/returns: executed successfully
Notice: /Stage[main]/Main/Exec[complex]/returns: The value is 2
Notice: /Stage[main]/Main/Exec[complex]/returns: executed successfully
Notice: Applied catalog in 0.05 seconds
</code>
请记住,Hiera可以进行插值
变量
要么
Hiera查找
,查找也可以在代码中完成
inline_epp
要么
inline_template
最终会评估。
的
注:这是一个示例,除非您信任您的用户并且非常喜欢头痛,否则您不应将Hiera输入传递给shell命令。
</强>