lib/vagrant-local/driver.rb in vagrant-local-0.0.1 vs lib/vagrant-local/driver.rb in vagrant-local-0.0.2

- old
+ new

@@ -35,12 +35,21 @@ else 'pfexec' end end - def state(machine) - vm_data = YAML.load_file("#{machine.name}.vmstate") + def state + data = [{ + 'name' => nil, + 'ec2_id' => nil, + 'state' => 'not_created', + 'public_ip' => nil + }] + vmstate_file = "#{@machine.name}.vmstate" + File.write(vmstate_file, data.to_yaml) unless File.exist?(vmstate_file) + + vm_data = YAML.load_file(vmstate_file) return :not_created unless vm_data.is_a?(Array) && !vm_data.empty? && vm_data.first.is_a?(Hash) vm_state = vm_data.first['state'] case vm_state when 'running' @@ -57,12 +66,12 @@ @executor.execute(...) end ## Begin installation def install(_uii) - config = @machine.config.vm.provisioners[0].config.extra_vars.to_json - command = "#{@pfexec} ansible-playbook ./providers/ansible/install.yml -e '#{config}'" + config = @machine.config.vm.provisioners[1].config.extra_vars.to_json + command = "#{@pfexec} ansible-playbook ./providers/ansible/playbook.yml --tags 'install' -e '#{config}'" _stdin, stdout, _stderr, wait_thr = Open3.popen3(command) puts stdout.readline until stdout.eof? wait_thr.value end @@ -90,12 +99,12 @@ execute_return end ## Boot the Machine def boot(uii) - config = @machine.config.vm.provisioners[0].config.extra_vars.to_json - command = "#{@pfexec} ansible-playbook ./providers/ansible/boot.yml -e '#{config}'" + config = @machine.config.vm.provisioners[1].config.extra_vars.to_json + command = "#{@pfexec} ansible-playbook ./providers/ansible/playbook.yml --tags 'boot' -e '#{config}'" uii.info(I18n.t('vagrant_local.start')) _stdin, stdout, _stderr, wait_thr = Open3.popen3(command) puts stdout.readline until stdout.eof? wait_thr.value end @@ -165,24 +174,24 @@ end # Halts the instance, first via shutdown command, then a halt. def halt(uii) provider_config = @machine.provider_config - config = @machine.config.vm.provisioners[0].config.extra_vars.to_json + config = @machine.config.vm.provisioners[1].config.extra_vars.to_json uii.info(I18n.t('vagrant_local.graceful_shutdown')) begin Timeout.timeout(provider_config.clean_shutdown_time) do - command = "#{@pfexec} ansible-playbook ./providers/ansible/halt.yml -e '#{config}'" + command = "#{@pfexec} ansible-playbook ./providers/ansible/playbook.yml --tags 'halt' -e '#{config}' " _stdin, stdout, _stderr, wait_thr = Open3.popen3(command) puts stdout.readline until stdout.eof? wait_thr.value end rescue Timeout::Error uii.info(I18n.t('vagrant_local.graceful_shutdown_failed') + provider_config.clean_shutdown_time.to_s) begin Timeout.timeout(provider_config.clean_shutdown_time) do - command = "#{@pfexec} ansible-playbook ./providers/ansible/halt.yml -e '#{config}'" + command = "#{@pfexec} ansible-playbook ./providers/ansible/playbook.yml --tags 'halt' -e '#{config}' " _stdin, stdout, _stderr, wait_thr = Open3.popen3(command) puts stdout.readline until stdout.eof? wait_thr.value end rescue Timeout::Error @@ -191,13 +200,14 @@ end end # Destroys the instance def destroy(id) - config = @machine.config.vm.provisioners[0].config.extra_vars.to_json - if state(@machine) == :stopped + # byebug + config = @machine.config.vm.provisioners[1].config.extra_vars.to_json + if state == :stopped id.info(I18n.t('vagrant_local.destroy')) - command = "#{@pfexec} ansible-playbook ./providers/ansible/destroy.yml -e '#{config}'" + command = "#{@pfexec} ansible-playbook ./providers/ansible/playbook.yml --tags 'destroy' -e '#{config}' " _stdin, stdout, _stderr, wait_thr = Open3.popen3(command) puts stdout.readline until stdout.eof? wait_thr.value end id.info(I18n.t('vagrant_local.destroyed'))