函数在Puppet中包含()与Anchor Pattern

时间:2014-06-28 13:24:25

标签: puppet

此帖子引用Puppet "require" not working as expected

是否可以用保持执行顺序的函数contain替换Anchor Pattern并阻止声明的浮出类。这两个清单如下:

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)

  include 'profile::java'

  anchor { 'profile::maven::begin': }

  class { '::maven::maven': version => $version, }

  anchor { 'profile::maven::end': }

  if ($settings) {
    create_resources('::maven::settings', $settings)
  }

  if ($environments) {
    create_resources('::maven::environment', $environments)
  }

  Anchor['profile::maven::begin'] -> Class['profile::java'] -> Class['::maven::maven'] -> Anchor['profile::maven::end']

}

class profile::java inherits profile::base {
  # Hiera
  $distribution = hiera('profile::java::distribution', 'jdk')
  $version = hiera('profile::java::version', 'present')

  anchor { 'profile::java::begin': }

  class { '::java':
    distribution => $distribution,
    version      => $version,
  }

  anchor { 'profile::java::end': }

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

  Anchor['profile::java::begin'] -> Class['::java'] -> File['profile-script:java.sh'] -> Anchor['profile::java::end']

}

由于Puppet 3.6.x中存在当前问题PUP-1597,因此必须重命名配置文件类,否则我们会获得Error: undefined method 'ref' for nil:NilClass。应用更改将导致:

class profile::mavenp 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)

  include 'profile::javap'

  class { '::maven::maven': version => $version, }
  contain 'maven::maven'

  if ($settings) {
    create_resources('::maven::settings', $settings)
  }

  if ($environments) {
    create_resources('::maven::environment', $environments)
  }

  Class['profile::javap'] -> Class['::maven::maven']

}

class profile::javap inherits profile::base {
  # Hiera
  $distribution = hiera('profile::java::distribution', 'jdk')
  $version = hiera('profile::java::version', 'present')

  class { '::java':
    distribution => $distribution,
    version      => $version,
  }
  contain 'java'

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

}

这些变化是否相同?

如果有人更好地了解如何使用个人资料/角色方法处理Puppet中的技术依赖,请不要犹豫,分享您的想法。

1 个答案:

答案 0 :(得分:0)

后一对类并不完全等同于前者。最大的问题是profile::javap。请注意,其模拟profile::java将此作为其依赖关系链的一部分:

Class['::java'] -> File['profile-script:java.sh']

班级profile::javap没有类似的东西。

我不能100%确定课程profile::mavenp是否等同于课程profile::maven,尽管我认为是。{你的意图会更清楚,如果前者包括

,我的不确定性将得到解决
contain 'profile::javap'

代替(或除此之外)

include 'profile::javap'