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

后端 未结 12 1518
一生所求
一生所求 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:56

    There are three resources that will do this nicely on an ubuntu system, specifically in use on 12.04 precise 64 bit by me.

    1. run apt-get-update at will when other recipes require

    2. install update-notifier-common package that gives us timestamps on updates

    3. check the timestamps and update periodically. In this case below after 86400 seconds.

    And here's those three recipes.

    execute "apt-get-update" do
      command "apt-get update"
      ignore_failure true
      action :nothing
    end
    
    package "update-notifier-common" do
      notifies :run, resources(:execute => "apt-get-update"), :immediately
    end
    
    execute "apt-get-update-periodic" do
      command "apt-get update"
      ignore_failure true
      only_if do
       File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
       File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - 86400
      end
    end
    

提交回复
热议问题