Ubuntu
使用 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 provision
,jdk 確實安裝正確。誰能幫我理解為什麼配置在 vagrant up 階段執行不順暢?另外如何簡化我的 java.pp 文件?
您的註釋
notify => Exec["apt-update"]
是Exec["add-apt-repository-oracle"]
必不可少的。沒有它,在實際添加儲存庫之前
apt-get update
可以自由執行;正在確保 repo 就位並且更新已經執行,但沒有什麼能確保這些以正確的順序發生。Package['oracle-java7-installer']
我是否可以推薦使用Puppet Labs
apt
模組,它會為您解決這個問題?apt::ppa { 'ppa:webupd8team/java': } package { 'oracle-java7-installer': ensure => installed, require => Apt::Ppa['ppa:webupd8team/java'], }