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

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

    For the recent Chef version, i.e version 14. You could also use https://docs.chef.io/resource_apt_update.html

    apt_update

    The below output was my experiment running that resource for chef_14.5.33 in local mode (zero):

    curl -O https://packages.chef.io/files/stable/chef/14.5.33/ubuntu/18.04/chef_14.5.33-1_amd64.de
    sudo dpkg -i chef_14.5.33-1_amd64.deb
    mkdir -p cookbooks/hello/recipes/ && echo "apt_update" > cookbooks/hello/recipes/default.rb
    
    sudo sh -c 'chef-client -z -o hello'
    [2018-10-12T10:25:30+00:00] WARN: No config file found or specified on command line, using command line options.
    Starting Chef Client, version 14.5.33
    [2018-10-12T10:25:32+00:00] WARN: Run List override has been provided.
    [2018-10-12T10:25:32+00:00] WARN: Run List override has been provided.
    [2018-10-12T10:25:32+00:00] WARN: Original Run List: []
    [2018-10-12T10:25:32+00:00] WARN: Original Run List: []
    [2018-10-12T10:25:32+00:00] WARN: Overridden Run List: [recipe[hello]]
    [2018-10-12T10:25:32+00:00] WARN: Overridden Run List: [recipe[hello]]
    resolving cookbooks for run list: ["hello"]
    Synchronizing Cookbooks:
      - hello (0.0.0)
    Installing Cookbook Gems:
    Compiling Cookbooks...
    Converging 1 resources
    Recipe: hello::default
      * apt_update[] action periodic (up to date)
    [2018-10-12T10:25:32+00:00] WARN: Skipping final node save because override_runlist was given
    [2018-10-12T10:25:32+00:00] WARN: Skipping final node save because override_runlist was given
    
    Running handlers:
    Running handlers complete
    Chef Client finished, 0/1 resources updated in 01 seconds
    

提交回复
热议问题