gpt4 book ai didi

java - puppet "require"未按预期工作

转载 作者:行者123 更新时间:2023-12-02 05:41:55 24 4
gpt4 key购买 nike

我有以下两个 list :

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 之前完全完成。

site.pp如下所示,不应修改以符合稍后的 puppet 角色配置文件方法(正在进行中):

node 'gamma.localdomain' {
include 'profile::java'
include 'profile::maven'
}

编译后,脚本开始下载 Maven 存档。为什么会这样

require '::profile::java'

无法保证执行顺序?有人知道如何实现所需的行为吗?

最佳答案

我认为这里的问题是 require profile::java 的范围是 profile::maven 类,所以所有资源 在后一个类中声明的依赖于 profile::java。但是,这不会传播到 profile::maven 声明的类,例如 maven::maven

为了实现这一点,您可以在这些类之间建立依赖关系

include profile::java
include maven::maven

Class[profile::java] -> Class[maven::maven]

这可能会导致依赖关系图变得相当复杂,所以要小心。使用 Anchor Pattern 可以避免这种情况.

请注意,require 函数的使用是 discouraged due to possible dependency cycle issues .

关于java - puppet "require"未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24433335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com