Puppet 中的函数 contains() 与锚模式 [英] Function contain() vs. Anchor Pattern in Puppet

查看:43
本文介绍了Puppet 中的函数 contains() 与锚模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章指的是 Puppet require"未按预期工作.

是否可以用函数contain来代替Anchor Pattern,保持执行顺序并阻止已声明的类浮出.两个清单如下所示:

Is it possible to replace the Anchor Pattern with the function contain maintaining execution order and hinder declared classes of floating out. The two manifests look as follows:

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.应用更改会导致:

Because of the current issue PUP-1597 in Puppet 3.6.x, the profile classes have to be renamed, otherwise we get Error: undefined method 'ref' for nil:NilClass. Applying the changes result in:

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 中的技术依赖有更好的想法,请随时分享您的想法.

If someone has a better idea of how to the deal with technologcial dependencies in Puppet using the profile/role approach, do not hesitate to share your thoughts.

推荐答案

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

The latter pair of classes are not completely equivalent equivalent to the former. The biggest issue is in profile::javap. Note that its analog profile::java has this as part of its dependency chain:

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

Class profile::javap 没有类似的东西.

Class profile::javap has no analog of that.

我不是 100% 确定 class profile::mavenp 是否等同于 class profile::maven,尽管我认为是.如果前者包括在内,你的意图会更清晰,我的不确定性也会得到解决

I'm not 100% certain whether class profile::mavenp is equivalent to class profile::maven, though I think it is. Your intent would be clearer and my uncertainty would be resolved if the former included

contain 'profile::javap'

代替(或除了)

include 'profile::javap'

这篇关于Puppet 中的函数 contains() 与锚模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆