Search code examples
vagrantchef-infrachef-solo

Conditionally provision ("vagrant provision") on "vagrant up"


Since I work in a team, I want to make the process of working with vagrant (and chef-solo) as smooth as possible.
When someone in the team changes the chef cookbooks, roles or whatever, I want all the other team members to automatically "receive" the changes by making vagrant re-provision (like running "vagrant provision") on the next "vagrant up", without every team member needing to know about it and re-provision manually.

I thought of accomplishing this by having the git post-receive hook script touch a file on the root project folder. Then, when "vagrant up" is called, it will check for this file existence. If the file exists - it will re-provision once the "up" is finished running.

Is there a better option of doing this? How?
If not, how can I do this ?

I know this question (Force Vagrant to re-provision or download a new box on next vagrant up) exists, but it's not exactly my situation (I'm interested specifically in provisioning, and less in the virtualbox machine itself - box, etc..).


Solution

  • Vagrant supports adding provisioners which run on every vagrant up, by adding :run => "always" to the provision line.

    You could add a provisioner which checks if any changes need to be made, then runs them. (Or, if the changes are repeatable, just runs them every time).

    "Run Always" is documented here: https://docs.vagrantup.com/v2/provisioning/basic_usage.html