Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continue Vagrant/Ansible provision script from error?

After I provision my Vagrant... I may get errors during provision... how do I restart from error, instead of doing everything from scratch ?

vagrant destroy -f && vagrant up

And I may get an error...

PLAY RECAP ******************************************************************** 
to retry, use: --limit @/path/to/playbook.retry

And I want to just resume from where it failed... it seems it can be done by the message... use --limit.... but when I use it in the vagrant context it doesn't work..

like image 947
smorhaim Avatar asked Apr 28 '15 20:04

smorhaim


2 Answers

You can edit the Vagrantfile and include the ansible.start_at_task variable.

Then you can re-run the provision with $ vagrant reload --provision

Vagrant Reload docs

However, because Ansible plays are idempotent you don't really need to do the start_at_task. You can just re-run the provision with the reload command above.

like image 191
Daniel Avatar answered Oct 26 '22 18:10

Daniel


You could do an ansible run with ansible-playbook on your vagrant box. The trick is to use the inventory file ansible has created. It is located in your .vagrant foler.

ansible-playbook playbook.yml -i vagrant/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --start-at-task='MY_TASK'

Vagrantfile: Assign your roles to a vagrant machines.

      config.vm.provision "ansible" do |ansible|
        ansible.verbose = "v"
        ansible.playbook = "../playbook.yml"
        ansible.groups = {
        "web"                 => ['vm01app'],
        "db"                  => ['vm01db'],
        }
      end
like image 29
Toon Avatar answered Oct 26 '22 17:10

Toon