Puppet - 如何使用 hiera 清单中定义的变量

Puppet - How to use variables defined in manifests with hiera

有没有办法使用 hiera 的某些清单中定义的变量?

我是这样试的:

manifest.pp

if $::ipaddress_bond0 {
  $primary_interface = 'bond0'
  notify{"$primary_interface":}
}
else {
  $primary_interface = 'eth0'
  notify{"$primary_interface":}
}

hiera.yaml

some_config:
  server:
    foo:
      bar: "%{::primary_interface}"

是的 possible。看例子:

test.pp

class nodes::test
{
  $value1 = 'abc'
  $value2 = hiera('test::value2')
  $value3 = hiera('test::value3')

  notify{ " v1 ${value1}": }
  notify{ " v2 ${value2}": }
  notify{ " v3 ${value3}": }
}

include nodes::test

test.yaml

test::value2: "%{value1}"
test::value3: "%{value4}"

运行 测试:

puppet apply  test.pp 

Notice: v1 abc

Notice: v2 abc

Notice: v3

请记住,在 hiera 中使用人偶变量是 really bad practice