Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Puppet 复杂的hiera查找不工作_Puppet_Hiera - Fatal编程技术网

Puppet 复杂的hiera查找不工作

Puppet 复杂的hiera查找不工作,puppet,hiera,Puppet,Hiera,我在yaml文件中有以下定义: keepalived: cluster_name: "cluster.example.lan" cluster_ip: "192.168.1.10" cluster_nic: "eth0" haproxy: bind_address: %{hiera('keepalived::cluster_ip')} 结果在bind\u address中,我得到了一个空字符串 如果我使用%{hiera('keepalived')}我已经打印了整

我在yaml文件中有以下定义:

keepalived:
    cluster_name: "cluster.example.lan"
    cluster_ip: "192.168.1.10"
    cluster_nic: "eth0"
haproxy:
    bind_address: %{hiera('keepalived::cluster_ip')}
结果在
bind\u address
中,我得到了一个空字符串

如果我使用
%{hiera('keepalived')}
我已经打印了整个散列,但是我只需要从这个散列中得到
cluster\u ip
。如何查找
群集\u ip

我想它不是

Hiera只能插入值为字符串的变量。(来自Puppet的数字也作为字符串传递,可以安全使用。)不能插入值为布尔值、非来自Puppet的数字、数组、哈希、资源引用或显式未定义值的变量

此外,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代码更改为如下所示:

keepalived:
  cluster_name: "cluster.example.lan"
  cluster_ip: "192.168.1.10"
  cluster_nic: "eth0"
haproxy:
  bind_address: %{hiera('keepalived.cluster_ip')}
对于数组,使用数组索引(基于0)而不是哈希键


请参见

自从接受了接受的答案后,hiera的最新版本已经改变了这一点,并且现在是可能的,如本答案所示。所以这取决于你对希拉的看法!