diff --git a/tripleo_common/inventory.py b/tripleo_common/inventory.py index d5b05bc6d..e21181536 100644 --- a/tripleo_common/inventory.py +++ b/tripleo_common/inventory.py @@ -16,7 +16,8 @@ # under the License. from collections import OrderedDict -import os.path +import os +import tempfile import yaml from heatclient.exc import HTTPNotFound @@ -309,5 +310,11 @@ class TripleoInventory(object): if var in inventory: inventory[var]['vars'].update(value) - with open(inventory_file_path, 'w') as inventory_file: + # Atomic update as concurrent tripleoclient commands can call this + inventory_file_dir = os.path.dirname(inventory_file_path) + with tempfile.NamedTemporaryFile( + 'w', + dir=inventory_file_dir, + delete=False) as inventory_file: yaml.dump(inventory, inventory_file, TemplateDumper) + os.rename(inventory_file.name, inventory_file_path)