我在yaml文件中有以下定义:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "192.168.1.10"
cluster_nic: "eth0"
haproxy:
bind_address: %{hiera('keepalived::cluster_ip')}因此,在bind_address中,我得到了一个空字符串。
如果我使用%{hiera('keepalived')},我已经打印了整个散列,但是我只需要从这个散列中输出cluster_ip。如何查找cluster_ip?
发布于 2015-01-09 13:51:15
我想这不是可能:
Hiera只能插值值为字符串的变量。(来自木偶的数字也作为字符串传递,可以安全地使用。)不能插值其值为布尔值、非来自木偶的数字、数组、散列、资源引用或显式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')}"发布于 2016-09-02 16:35:41
希拉用。在字符串内插中查找数组或散列中的子元素。将hiera代码更改如下:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "192.168.1.10"
cluster_nic: "eth0"
haproxy:
bind_address: %{hiera('keepalived.cluster_ip')}对于数组,使用数组索引(基于0)而不是哈希键。
请参阅插值散列或数组元素
https://stackoverflow.com/questions/27860333
复制相似问题