Merge pull request #7190 from electrofelix/ansible-parallel-race
Fix a race condition in the concurrent generations of the ansible inventory file, while running `vagrant up --parallel`. Closes GH-6526
This commit is contained in:
commit
6ee69e3150
|
@ -109,6 +109,7 @@ module Vagrant
|
||||||
@provider_options = provider_options
|
@provider_options = provider_options
|
||||||
@ui = Vagrant::UI::Prefixed.new(@env.ui, @name)
|
@ui = Vagrant::UI::Prefixed.new(@env.ui, @name)
|
||||||
@ui_mutex = Mutex.new
|
@ui_mutex = Mutex.new
|
||||||
|
@state_mutex = Mutex.new
|
||||||
|
|
||||||
# Read the ID, which is usually in local storage
|
# Read the ID, which is usually in local storage
|
||||||
@id = nil
|
@id = nil
|
||||||
|
@ -507,11 +508,17 @@ module Vagrant
|
||||||
# master index.
|
# master index.
|
||||||
uuid = index_uuid
|
uuid = index_uuid
|
||||||
if uuid
|
if uuid
|
||||||
entry = @env.machine_index.get(uuid)
|
# active_machines provides access to query this info on each machine
|
||||||
if entry
|
# from a different thread, ensure multiple machines do not access
|
||||||
entry.state = result.short_description
|
# the locked entry simultaneously as this triggers a locked machine
|
||||||
@env.machine_index.set(entry)
|
# exception.
|
||||||
@env.machine_index.release(entry)
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,15 @@ module VagrantPlugins
|
||||||
inventory_file = Pathname.new(File.join(inventory_path, 'vagrant_ansible_inventory'))
|
inventory_file = Pathname.new(File.join(inventory_path, 'vagrant_ansible_inventory'))
|
||||||
@@lock.synchronize do
|
@@lock.synchronize do
|
||||||
if !File.exists?(inventory_file) or inventory_content != File.read(inventory_file)
|
if !File.exists?(inventory_file) or inventory_content != File.read(inventory_file)
|
||||||
inventory_file.open('w') do |file|
|
begin
|
||||||
file.write(inventory_content)
|
# 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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue