Puppet “require” not working as expected

拥有回忆 提交于 2019-12-25 06:04:04

问题


I have the following two manifests:

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)
  }
}

and

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'),
  }

}

I want that profile::java has completely finished before profile::maven is executed.

The site.pplooks 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'
} 

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?


回答1:


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.

Note that use of the require function is discouraged due to possible dependency cycle issues.




回答2:


Since at least Puppet 3.5 you can use "contain" to ensure that everything inside profile::java completes before profile::maven. The following addition to profile::java would be required:

class profile::java inherits profile::base {
  ...
  contain '::maven::maven'
  ...
}

Answering this old, answered question as it comes up first when googling "puppet require does not work"



来源:https://stackoverflow.com/questions/24433335/puppet-require-not-working-as-expected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!