问题描述
我有以下两个清单:
class profile::maven inherits profile::base {
# Hiera
$version = hiera('profile::maven::version', '3.2.1')
$settings = hiera_hash('profile::maven::settings', undef)
$environments = hiera_hash('profile::maven::environments', undef)
# Dependencies
require '::profile::java'
# Modules
class { '::maven::maven':
version => $version,
}
if ($settings) {
create_resources('::maven::settings', $settings)
}
if ($environments) {
create_resources('::maven::environments', $environments)
}
}
和
class profile::java inherits profile::base {
# Hiera
$distribution = hiera('profile::java::distribution', 'jdk')
$version = hiera('profile::java::version', 'present')
# Modules
class { '::java':
distribution => $distribution,
version => $version,
}
# Parameters
$java_home = $::java::java_home
file { 'profile-script:java.sh':
ensure => present,
path => '/etc/profile.d/java.sh',
content => template('profile/java.sh.erb'),
}
}
我希望 profile::java
在 profile::maven
执行之前已经完成.
I want that profile::java
has completely finished before profile::maven
is executed.
site.pp
如下所示,不应修改以符合 puppet 的角色配置文件方法(正在进行中):
The site.pp
looks as follows and should not be modified in order to comply with puppet's role-profile approach later (work in progress):
node 'gamma.localdomain' {
include 'profile::java'
include 'profile::maven'
}
编译后脚本开始下载 maven 存档.为什么
After compilation the scripts starts with downloading the maven archive. Why does
require '::profile::java'
不保证执行顺序?有人知道如何实现所需的行为吗?
not ensure the execution order? Has someone an idea how to achieve the desired behavior?
推荐答案
我认为这里的问题在于 require profile::java
的范围是 profile::maven
类,所以在后一个类中声明的所有资源都依赖于profile::java
.但是,这不会传播到 profile::maven
声明的类,例如 maven::maven
.
I believe that the problem here is that the require profile::java
is scoped to the profile::maven
class, so all resources declared in the latter class depend on profile::java
. However, this will not propagate to classes that profile::maven
declares, such as maven::maven
.
为此,您可以在这些类之间建立依赖关系
To achieve that, you can establish a dependency among those classes
include profile::java
include maven::maven
Class[profile::java] -> Class[maven::maven]
这可能会导致依赖关系图的复杂性,所以要小心.使用锚模式可以避免这种情况.
This can incur substantial complexity in the dependency graph, so be wary of that. This can be avoided using the Anchor Pattern.
请注意,不建议使用 require 函数,因为可能存在依赖循环问题.
这篇关于傀儡“需要"没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!