diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index de703842c..3806366d0 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -109,6 +109,7 @@ module Vagrant @provider_options = provider_options @ui = Vagrant::UI::Prefixed.new(@env.ui, @name) @ui_mutex = Mutex.new + @state_mutex = Mutex.new # Read the ID, which is usually in local storage @id = nil @@ -507,11 +508,17 @@ module Vagrant # master index. uuid = index_uuid if uuid - entry = @env.machine_index.get(uuid) - if entry - entry.state = result.short_description - @env.machine_index.set(entry) - @env.machine_index.release(entry) + # active_machines provides access to query this info on each machine + # from a different thread, ensure multiple machines do not access + # the locked entry simultaneously as this triggers a locked machine + # exception. + @state_mutex.synchronize do + entry = @env.machine_index.get(uuid) + if entry + entry.state = result.short_description + @env.machine_index.set(entry) + @env.machine_index.release(entry) + end end end diff --git a/plugins/provisioners/ansible/provisioner/host.rb b/plugins/provisioners/ansible/provisioner/host.rb index 83a614a10..5b35749d1 100644 --- a/plugins/provisioners/ansible/provisioner/host.rb +++ b/plugins/provisioners/ansible/provisioner/host.rb @@ -139,8 +139,15 @@ module VagrantPlugins inventory_file = Pathname.new(File.join(inventory_path, 'vagrant_ansible_inventory')) @@lock.synchronize do if !File.exists?(inventory_file) or inventory_content != File.read(inventory_file) - inventory_file.open('w') do |file| - file.write(inventory_content) + begin + # ansible dir inventory will ignore files starting with '.' + inventory_tmpfile = Tempfile.new('.vagrant_ansible_inventory', inventory_path) + inventory_tmpfile.write(inventory_content) + inventory_tmpfile.close + File.rename(inventory_tmpfile.path, inventory_file) + ensure + inventory_tmpfile.close + inventory_tmpfile.unlink end end end