在Puppet中包含已定义的资源类型

时间:2015-12-08 07:27:01

标签: puppet

我正在尝试创建一个在其他资源之前的已定义资源类型(:: apt :: ppa)的实例。我正在使用PuppetLabs Apt Module

通过模块添加新存储库时,定义的类型包含一个exec statement,它通知apt :: update,以便可以正确安装任何可能需要的包。但是,当我运行我的下面的代码时,在我尝试安装Java之后,通知会被调度,从而导致Java安装失败。我已经尝试在apt :: ppa声明周围放置锚点,但这没有帮助。我还能做什么?

class rap::java(
  $version = '7',
) {
  $package = "oracle-java${version}-installer"

  apt::ppa { 'ppa:webupd8team/java': } ->
  exec { 'accept-java-license':
    command => "/bin/echo ${package} shared/accepted-oracle-license-v1-1 select true | /usr/bin/sudo /usr/bin/debconf-set-selections",
    unless  => "/usr/bin/debconf-show ${package} | grep 'shared/accepted-oracle-license-v1-1: true'",
  } ->
  class { '::java':
    package      => $package,
    distribution => 'oracle-jre',
  }

  file_line { 'java_environment':
    path => '/etc/environment',
    line => "JAVA_HOME=\"/usr/lib/jvm/java-${version}-oracle\"",
  }
}

1 个答案:

答案 0 :(得分:1)

我认为问题在于你需要在你所做的类中包含apt类才能获得正确的排序。

这适用于我在一个新的精确盒子上:

class rap::java(
  $version = '7',
) {
  $package = "oracle-java${version}-installer"

  include apt

  apt::ppa { 'ppa:webupd8team/java':
     package_manage => true,
  }

  exec { 'accept-java-license':
    command => "/bin/echo ${package} shared/accepted-oracle-license-v1-1 select true | /usr/bin/sudo /usr/bin/debconf-set-selections",
    unless  => "/usr/bin/debconf-show ${package} | grep 'shared/accepted-oracle-license-v1-1: true'",
  }

  class { '::java':
    package      => $package,
    distribution => 'oracle-jre',
    require => [
      Apt::Ppa['ppa:webupd8team/java'],
      Exec["accept-java-license"],
    ]
  }

  file_line { 'java_environment':
    path => '/etc/environment',
    line => "JAVA_HOME=\"/usr/lib/jvm/java-${version}-oracle\"",
  }
}

运行日志:

Notice: Compiled catalog for precise64 in environment production in 0.78 seconds
Notice: /Stage[main]/Apt/File[preferences]/ensure: created
Notice: /Stage[main]/Rap::Java/Exec[accept-java-license]/returns: executed successfully
Notice: /Stage[main]/Rap::Java/File_line[java_environment]/ensure: created
Notice: /Stage[main]/Apt/Apt::Setting[conf-update-stamp]/File[/etc/apt/apt.conf.d/15update-stamp]/ensure: defined content as '{md5}0962d70c4ec78bbfa6f3544ae0c41974'
Notice: /Stage[main]/Rap::Java/Apt::Ppa[ppa:webupd8team/java]/Package[python-software-properties]/ensure: created
Notice: /Stage[main]/Rap::Java/Apt::Ppa[ppa:webupd8team/java]/Exec[add-apt-repository-ppa:webupd8team/java]/returns: executed successfully
Notice: /Stage[main]/Apt::Update/Exec[apt_update]: Triggered 'refresh' from 1 events
Notice: /Stage[main]/Java/Package[java-common]/ensure: created
Notice: /Stage[main]/Java/Package[java]/ensure: created
Notice: Applied catalog in 39.58 seconds

为了进一步扩展问题,通常将标准设置的阻止程序运行到运行阶段(documented here)。

所以我可能会将所有各种repo setup puppet代码移动到其他先决条件的预运行阶段(通常你放入repo设置),运行阶段将始终在主阶段之前运行,所以你不要必须担心明确设置每个包上设置repos的要求。这使得对回购和先决条件的更改变得更加容易