2012-10-23 12 views
10

Attualmente sto usando lo chef per installare il pacchetto JDK RPM ma il problema è che lo fa ogni volta anche se il pacchetto è già stato scaricato e installato. Ho provato a trovare un'opzione per il controllo prima di installare ma non ce n'era. C'è un modo per aggirare questo in modo che io possa saltare i pacchetti che sono già installati? La gestione dei pacchetti di Debian salta i pacchetti già installati per impostazione predefinita, ma il gestore pacchetti RPM non sembra farlo.Come far controllare lo chef per il pacchetto RPM e poi installarlo?

[Tue, 23 Oct 2012 10:34:32 -0500] INFO: Processing remote_file[/var/chef/cache/jdk-1.6-u30-linux-amd64.rpm] action create_if_missing (sun_java::default line 18) 
[Tue, 23 Oct 2012 10:34:36 -0500] INFO: Processing package[jdk-1.6-u30-linux-amd64.rpm] action upgrade (sun_java::default line 25) 
[Tue, 23 Oct 2012 10:37:15 -0500] INFO: Processing bash[update-alternatives java] action nothing (sun_java::default line 40) 

la ricetta è mostrato di seguito:

urlVersion = "1."+node["sun_java"]["version"].sub(/[u]/, "-u") 
    node.default["sun_java"]["rpm_url"] = "http://***/#{urlVersion}/jdk-#{urlVersion}-linux-#{node["sun_java"]["arch"]}.rpm" 

    #Check that we are using the .rpm file because of the recent change 
    if File.extname(File.basename(node["sun_java"]["rpm_url"]))!=".rpm" 
     raise "You must use the jdk*.rpm file to install the Sun JDK. You can get it from the jdk*-rpm.bin file by running the command './jdk*-rpm.bin -x'" 
    end 

    javaRPM = File.basename(node["sun_java"]["rpm_url"]) 

    remote_file "#{Chef::Config[:file_cache_path]}/#{javaRPM}" do 
     action :create_if_missing 
     source node["sun_java"]["rpm_url"] 
     mode "0755" 
     backup false 
    end 

    package javaRPM do 
     action :install 
     source "#{Chef::Config[:file_cache_path]}/#{javaRPM}" 
     options "--nogpgcheck" # sun/oracle doesn't sign their RPMs o_O 
     notifies :run, "bash[update-alternatives java]", :immediately 
    end 

    javaHomeFolder = "/usr/java/jdk1.#{node["sun_java"]["version"].sub(/[u]/, ".0_")}" 
    jdkFolder = "#{javaHomeFolder}/bin" 
    slaveString = "" 

    node["sun_java"]["update_slaves"].each do |java_bin| 
     slaveString = slaveString + "--slave \"/usr/bin/#{java_bin}\" \"#{java_bin}\" \"#{jdkFolder}/#{java_bin}\" " 
    end 

    bash "update-alternatives java" do 
     action :nothing 
     code <<-EOH 
     update-alternatives --install "/usr/bin/java" "java" "#{jdkFolder}/java" 1 #{slaveString} 
     update-alternatives --set java #{jdkFolder}/java 
     EOH 
    end 

    #Remove old environment then notify new environment to be created 
    ruby_block "delete_environement" do 
      block do 
       editBashrc = Chef::Util::FileEdit.new("/etc/profile") 
        editBashrc.search_file_delete_line(/^.*#JAVA_HOME environment settings.*$/) 
        editBashrc.search_file_delete_line(/^.*#Auto-generated by Chef Cookbook sun_java.*$/) 
        editBashrc.search_file_delete_line(/^.*export JAVA_HOME=.*$/) 
        editBashrc.write_file 
      end 
      action :create 
    end 

    #create environment of root user 
    execute "create_environment" do 
     user "root" 
     command "echo -e '#JAVA_HOME environment settings\n#Auto-generated by Chef Cookbook sun_java\nexport JAVA_HOME=#{javaHomeFolder}' >> /etc/profile" 
    end 
+0

si può mostrare la parte della vostra ricetta dove si chiama tali elementi? – jstim

+0

@jstim Ho aggiunto la ricetta. – noMAD

risposta

14

So che questo è vecchio, ma credo che si desidera:

remote_file "your-remote-file" do 
    ... 
    not_if "rpm -qa | grep -qx 'your-package'" 
end 
2

non ho familiarità con RPM, ma è possibile verificare come chef learns if the package is already installed (il metodo load_current_resource). È possibile implementare qualcosa di simile nella vostra ricetta e aggiungere questa condizione file_remoto:

remote_file "#{Chef::Config[:file_cache_path]}/#{javaRPM}" do 
    not_if { [your_code_that_checks_if_package_installed] } 
    ... 
end 
0

Chef fornire una risorsa per rpm_packages. e si possono trovare un sacco di numero di esempi che mostrano come chef verify se un pacchetto è installato

1

È prima possibile rimuovere il pacchetto utilizzando ignore_failure e poi installarlo

package 'package_name' 
    ignore_failure true 
    action   :remove 
end 

Poi prendete il file

remote_file localPath do 
    source packageUrl 
    mode 0644 
    checksum checkSum 
end 

Quindi installare il pacchetto di

package packageName do 
     source localPath 
     action :install 
     allow_downgrade true 
end 

Funzionerà con qualsiasi tipo di pacchetto. Idealmente per rpm non è necessario rimuovere il pacchetto. allow_downgrade dovrebbe funzionare. Ma non ha funzionato per me.

Per uso checksum curl packageUrl | shasum -a 256

Problemi correlati