How can I get Chef to run apt-get update before running other recipes

后端 未结 12 1511
一生所求
一生所求 2021-01-31 02:01

Right now I have the following in my Vagrantfile:

config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = \"cookbooks\"
    chef.add_recipe \"apt\"
           


        
12条回答
  •  失恋的感觉
    2021-01-31 02:58

    The simplest and most direct way to solve the problem is by applying the following patch (h/t @ashchristopher):

    https://github.com/wil/cookbooks/commit/a470a4f68602ec3bf3374830f4990a7e19e9de81

    The problem is that the postgresql::client recipe runs the install action on the package resources at postgresql/recipes/client.rb:39 and 44 at compile-time rather than run-time like normal (h/t Tim Potter), causing them to be evaluated by Chef (and thus installed) before anything else runs.

    pg_packages.each do |pg_pack|
      package pg_pack do
        action :nothing
      end.run_action(:install)
    end
    
    gem_package "pg" do
      action :nothing
    end.run_action(:install)
    

    I believe this is done in service of the database cookbook's postgres provider, which depends on the postgresql cookbook and relies on the pg gem being installed before it will compile. Applying the above patch may break the database cookbook.

    The other alternative solution would be to create a recipe which runs apt-get update also at compile time and put it in your run_list before the postgresql cookbook. In its simplest form that would probably be something like:

    execute "apt-get update" do
      action :nothing
    end.run_action(:install)
    

提交回复
热议问题