使用 Puppet 和 Vagrant 将 Oracle JDK 部署到 VirtualBox 中

使用 Puppet 和 Vagrant 将 Oracle JDK 部署到 VirtualBox 中

我在尝试着使用 Vagrant/Puppet 安装 Oracle 的 jdk

这是我的相关部分Vagrant file

  config.vm.provision :puppet, :module_path => "puppet/modules" do |puppet|
     puppet.options = "--verbose --debug"       
     puppet.manifests_path = "puppet/manifests"
     puppet.manifest_file  = "java.pp"
  end

这是我的java.pp木偶文件:

class java {

  package { "python-software-properties":
    require => Exec['apt-update'],
    ensure => installed
  }

  exec { 'add-webupd8-key':
    command => 'sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886',
    path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ],
  }

  exec { 'apt-update':
    command => 'sudo apt-get update',
    path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ],
  }

  exec { "add-apt-repository-oracle":
    command => "sudo add-apt-repository -y ppa:webupd8team/java",
    path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ],
    require => [Exec["add-webupd8-key"],Package["python-software-properties"]],
#    notify => Exec["apt-update"]
  }

  exec {
    'set-licence-selected':
      command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections';

    'set-licence-seen':
      command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections';
  }

  package { 'oracle-java7-installer':
#    ensure => "7u40-0~webupd8~0",
    ensure => installed,
    require => [Exec['add-apt-repository-oracle'], Exec['apt-update'], Exec['set-licence-selected'], Exec['set-licence-seen']],
  }
}

include java

当我第一次运行时vagrant up,我总是收到以下错误:

debug: Puppet::Type::Package::ProviderApt: Executing '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install oracle-java7-installer'
err: /Stage[main]/Java/Package[oracle-java7-installer]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install oracle-java7-installer' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package oracle-java7-installer

当我下一个运行一个vagrant provisionjdk 确实安装正确

有人能帮我理解为什么在 vagrant up 阶段配置无法顺利运行吗?此外,我该如何简化我的 java.pp 文件?

答案1

您的注释掉的notify => Exec["apt-update"]Exec["add-apt-repository-oracle"]至关重要的。

如果没有它,就apt-get update可以自由运行存储库实际上已被添加;Package['oracle-java7-installer']正在确保存储库已到位并且更新已运行,但没有什么可以确保这些操作以正确的顺序发生。

我建议使用Puppet Labsapt模块,相反,哪一个可以帮您解决这个问题?

apt::ppa { 'ppa:webupd8team/java': }

package { 'oracle-java7-installer':
  ensure   => installed,
  require  => Apt::Ppa['ppa:webupd8team/java'],
}

相关内容