Function contain() vs. Anchor Pattern in Puppet

做~自己de王妃 提交于 2019-12-11 12:19:57

问题


This post refers to Puppet "require" not working as expected.

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']

}

and

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']

}

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']

}

and

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

}

Are these changes equivalent?

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.


回答1:


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 has no analog of that.

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'

instead of (or in addition to)

include 'profile::javap'


来源:https://stackoverflow.com/questions/24467249/function-contain-vs-anchor-pattern-in-puppet

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