我在yaml文件中有以下定义:
的keepalived: cluster_name:“cluster.example.lan” cluster_ip:“192.168.1.10” cluster_nic:“eth0”HAProxy的: bind_address:%{hiera(’…
我认为不是 可能:
Hiera只能插入值为的变量 的 字符串 强> 。 ( 的 数字 强> 来自Puppet也可以作为字符串传递,并且可以安全使用。)您不能插入值为布尔值的数字,数字不是来自Puppet,数组,哈希,资源引用或显式的undef值。 此外,Hiera不能插入个人 的 任何数组或散列的元素,即使该元素的值是一个字符串。 强>
Hiera只能插入值为的变量 的 字符串 强> 。 ( 的 数字 强> 来自Puppet也可以作为字符串传递,并且可以安全使用。)您不能插入值为布尔值的数字,数字不是来自Puppet,数组,哈希,资源引用或显式的undef值。
此外,Hiera不能插入个人 的 任何数组或散列的元素,即使该元素的值是一个字符串。 强>
您始终可以将cluster_ip定义为变量:
common::cluster_ip: "192.168.1.10"
而不是使用它:
keepalived: cluster_name: "cluster.example.lan" cluster_ip: "%{hiera('common::cluster_ip')}" cluster_nic: "eth0" haproxy: bind_address: "%{hiera('common::cluster_ip')}"
Hiera使用。在字符串插值中查找数组或散列中的子元素。将您的hiera代码更改为如下所示:
keepalived: cluster_name: "cluster.example.lan" cluster_ip: "192.168.1.10" cluster_nic: "eth0" haproxy: bind_address: %{hiera('keepalived.cluster_ip')}
对于数组,使用数组索引(基于0)而不是散列键。
看到 内插散列或数组元素