问题原文
原帖链接 · Mojo · CC BY-SA 4.0
So suppose in a very specific hiera YAML file I define a variable, such as "env_name".
env_name: "dev-unstable"
Now in a more general hiera file I'd like to interpolate that variable into a string.
server_name: "service-%{env_name}.%{::domain}"
My testing seems to imply that hiera variables from elsewhere in the hierarchy aren't made available for interpolation in general cases. Is that true, unfortunately?
已采纳解答
原帖链接 · daff · CC BY-SA 3.0
You can use Hiera lookup functions within Hiera. Documentation here: https://docs.puppetlabs.com/hiera/1/variables.html#using-lookup-functions
In your case you would use:
server_name: "service-%{hiera('env_name')}.%{::domain}"
This is a priority lookup and will get the value for the key env_name from the highest (most specific) hierarchy level in which it finds the key.
This requires Hiera 1.3 or higher.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
