I'm using vagrant and ansible to provision a virtual machine and that works fine. The ansible playbook clones a git repo, installs it and runs a service daemon.
I'd also like to have a vagrant command that executes a separate "update" playbook that pulls the latest from the git repo, installs and restarts the daemon.
Something like this usage would be nice.
Vagrant.configure("2") do |config|
# Default
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
# Update
config.vm.provision "ansible", name="update" do |ansible|
ansible.playbook = "update.yml"
end
end
Then I could run it with vagrant --provision-with update
. Is something like this possible? I'd like to avoid having to ssh into the box to run an update like this.
On the first vagrant up that creates the environment, provisioning is run. If the environment was already created and the up is just resuming a machine or booting it up, they will not run unless the --provision flag is explicitly provided. When vagrant provision is used on a running environment.
There are a lot of Ansible options you can configure in your Vagrantfile . Visit the Ansible Provisioner documentation for more information. This will start the VM, and run the provisioning playbook (on the first VM startup). This will re-run the playbook against the existing VM.
Ansible, Terraform and Vagrant each perform automation in some way, but their functionality is decidedly different. Vagrant can incorporate other automation tools, like Ansible, Puppet or Chef, to perform specific VM configuration tasks.
The Ansible/F5 provisioner is an opensource provisioning tool. It is a collection of Ansible playbooks packaged to build and tear down F5 and application infrastructure. It can also be used to scale the infrastructure as needed by the user.
I'm not sure why the person's answer was deleted because it was correct. As of vagrant 1.7.0 you can name provisions.
The following worked:
Vagrant.configure("2") do |config|
# Default
config.vm.provision "main", type: "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
# Update
config.vm.provision "update", type: "ansible" do |ansible|
ansible.playbook = "update.yml"
end
end
You can use vagrant provision --provision-with <foo>
to then execute either one.
However, if you do vagrant up
, all provisioners will run, which is not desired. As a solution, I run vagrant up --no-provision
then vagrant provision --provision-with main
as the default, which I put in a Makefile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With