我在yaml文件中有以下定义:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "192.168.1.10"
cluster_nic: "eth0"
haproxy:
bind_address: %{hiera('keepalived::cluster_ip')}
Run Code Online (Sandbox Code Playgroud)
结果bind_address我得到一个空字符串.
如果我使用%{hiera('keepalived')}我已经打印了整个哈希,但我只需cluster_ip要从这个哈希.我该如何查找cluster_ip?
我认为这是不可能的:
Hiera只能插入值为字符串的变量.(来自Puppet的数字也作为字符串传递,可以安全使用.)您不能插入值为布尔值的数字,数字不是来自Puppet,数组,哈希,资源引用或显式的undef值.
此外,Hiera不能插的个体的任何阵列或散列的元件,即使该元素的值是字符串.
您始终可以将cluster_ip定义为变量:
common::cluster_ip: "192.168.1.10"
Run Code Online (Sandbox Code Playgroud)
而不是使用它:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "%{hiera('common::cluster_ip')}"
cluster_nic: "eth0"
haproxy:
bind_address: "%{hiera('common::cluster_ip')}"
Run Code Online (Sandbox Code Playgroud)