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

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

    just a friendly reminder that adding all those recipes inside the vagrant provision can quickly become unmanageable.

    A better pattern is to create a chef role chef/my-fancy-role.rb

    # Name of the role should match the name of the file
    name "my-fancy-role"
    
    # Run list function we mentioned earlier
    run_list(
        "recipe[apt]",
        "recipe[build-essential]",
        "recipe[chef-redis::source]",
        "recipe[openssl]"
    )
    

    And then add this role to the Vagrantfile provisioning section:

    config.vm.provision :chef_solo do |chef|
      chef.roles_path = "chef/roles"
      chef.cookbooks_path = ["chef/site-cookbooks", "chef/cookbooks"]
      chef.add_role "my-fancy-role"
    end
    

提交回复
热议问题