[英]Puppet create variable names using hiera
我希望Puppet根据与环境关联的hiera文件创建一个不同的变量名。 我想要这样做是因为我希望Puppet使用与特定网络接口关联的IP地址。 理想情况下,网络接口将位于hiera文件中。 这样,您可以将ip_address变量名称与hiera文件中定义的网络接口连接起来,看起来像这样。
::ipaddress_{$network_interface_from_hiera_file}
这可能吗?
现在,我有以下内容,但我认为有更好的实现方法。 如果网络接口更改,我将不得不添加另一种情况。
if $environment == 'production' {
$client_address = $::ipaddress_enp130s0f0
} else {
$client_address = $::ipaddress_eth2
}
听起来您正在使用Puppet进行eval
,就像您在Shell和Perl其他语言中一样,据我所知,还没有。
我可能会使用一个总是返回我关心的IP地址的自定义事实。 当然,那么您需要解决如何将自定义事实提供给您的机队的问题。
另一个解决方案可能是使用Hiera的分层查找:
在hiera.yaml中:
:hierarchy:
- %{::node_environment}
- common
在common.yaml中:
---
myclass::client_address: "%{::ipaddress_eth2}"
在production.yaml中:
---
myclass::client_address: "%{::ipaddress_enp130s0f0}"
最后,请注意,您可以在Hiera中查找值,请参见此处 。 可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.