You can just add multiple provisioners. So after your first config.vm.provision :chef_solo
block just add another one applying the recipe you want to run after the first deployment.
How to run a chef recipe after vagrant box provisioned
-
29-05-2022 - |
質問
I'm using Vagrant + Berkshelf + Chef Solo to mirror behavior of my production AWS OpsWorks boxes on my development machine.
I can get the vagrant box up just fine, but now, after it has been provisioned, I want to be able to run a different Chef recipe from the cookbooks used during provisioning. I want to do this because I'm trying to emulate OpsWorks' behavior: they let me run a deploy
recipe with the push of a button. I want to be able to either use vagrant or chef-solo inside my vagrant box to run that same recipe.
I think I can solve this by adding a recipe to the provisioning process that builds up different solo.rb
config files for the different on-demand recipes I want to run. These config files would point to the Vagrant/Berkshelf cookbooks_path
(which is /tmp/vagrant-chef-1/
for me) and then set the run list to the appropriate recipe. These config files would then be used by chef-solo.
I get the feeling that someone has solved this problem before in a more elegant way. Is there a better way to do this?
If not, does anyone know a way from within Vagrant or within a recipe to find the cookbook path so I don't have to hardcode /tmp/vagrant-chef-1/
into my solo.rb
config files?
解決
他のヒント
Actual chef-solo configuration and attributes are stored in /tmp/vagrant-chef/solo.rb
and /tmp/vagrant-chef/dna.json
files within your vagrant box.
Executing the full chef provisioning:
sudo chef-solo -c /tmp/vagrant-chef/solo.rb -j /tmp/vagrant-chef/dna.json
Overriding the defined run list and running just a single recipe (e.g. memcached):
sudo chef-solo -c /tmp/vagrant-chef/solo.rb -j /tmp/vagrant-chef/dna.json -o recipe[memcached]