Hiera 中的“calling_class”查找变量让我头疼。
给定这样的 hiera 配置:
---
:backends: yaml
:yaml:
:datadir:
:hierarchy:
- "node/%{::clientcert}"
- "profile/%{calling_class}"
- "roles/%{calling_class}"
- common
:logger: console
Puppet 中的 role.pp 具有以下内容:
class role::base {
notify { "output scope 1":
message => inline_template("scope='<%= scope.source.name %>'"),
}
$profiles = hiera_array('role::profiles', [])
notify { "Including profiles: ${profiles}": }
# include $profiles
}
class role::app inherits role::base{
notify { "output scope 2":
message => inline_template("scope='<%= scope.source.name %>'"),
}
$profiles = hiera_array('role::profiles', [])
notify { "Including profiles: ${profiles}": }
}
并roles/role::app.yaml
带有以下内容:
---
role::profiles:
- webserver
- application
我希望看到这样的东西:
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Finished catalog run in 0.11 seconds
但这就是我得到的:
Notice: Including profiles:
Notice: scope='role::base'
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Finished catalog run in 0.11 seconds
似乎当一个类被继承(或包含,以任何一种方式发生)时,Hiera 中的“calling_class”被设置为继承的类,而不是进行继承的类。我是否遗漏了什么,或者这就是 Hiera 应该工作的方式?我认为继承一个类会将其设置scope.source.name
为子类,而不是父类。