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
|
||||
@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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue