diff --git a/sandboxcreator/io/writer.py b/sandboxcreator/io/writer.py index 6b11edc3869a0e666b05de9759c3cef950fa6dce..9dee8c73ce54b4dcb38ccae4f28446c56df65fc3 100644 --- a/sandboxcreator/io/writer.py +++ b/sandboxcreator/io/writer.py @@ -1,6 +1,7 @@ import os from pathlib import Path import shutil +import stat from typing import Union, List, Dict import jinja2 @@ -57,6 +58,12 @@ class Writer: output = template.render(data=data, ruby_variables=ruby_variables) Writer._write_to_file(output_file, output) + @staticmethod + def _on_rmtree_error(func, path, exc_info): + """On error during rmtree, try to make the file writable""" + os.chmod(path, stat.S_IWRITE) + os.unlink(path) + @staticmethod def clone_git_repository(repository: str, location: Path, cloned_dir: str) -> None: """Clone a git repository to the provided location and removes .git @@ -74,7 +81,8 @@ class Writer: raise RuntimeError(f"Could not clone repository: {repository}") try: - shutil.rmtree(location.joinpath(cloned_dir).joinpath(".git")) + shutil.rmtree(location.joinpath(cloned_dir).joinpath(".git"), + onerror=Writer._on_rmtree_error) except OSError: pass diff --git a/sandboxcreator/resources/conf/configuration.yml b/sandboxcreator/resources/conf/configuration.yml index 6ddc6b37095d5f44ca2c93b3c8a68a910e7ebea1..d790f63e59a6702a1cac5cd6829ab711048b9916 100644 --- a/sandboxcreator/resources/conf/configuration.yml +++ b/sandboxcreator/resources/conf/configuration.yml @@ -32,6 +32,7 @@ preconfig_group_vars: preconfig/group_vars/ provisioning_dir: provisioning provisioning_playbook: provisioning/playbook.yml provisioning_inventory: provisioning/hosts.yml +provisioning_group_vars: provisioning/group_vars/ user_extra_vars: provisioning/extra_vars.yml #Git repositories diff --git a/sandboxcreator/resources/templates/vagrantfile.j2 b/sandboxcreator/resources/templates/vagrantfile.j2 index 77b6752400aa24b099aa8c4a57b62fb9c0dfff31..48473535ebc7825260a8a4e3a09a4accbf3ee584 100644 --- a/sandboxcreator/resources/templates/vagrantfile.j2 +++ b/sandboxcreator/resources/templates/vagrantfile.j2 @@ -1,4 +1,4 @@ -# Generated by Cyber Sandbox Creator 2.0.0 +# Generated by Cyber Sandbox Creator 2.0.1 # https://gitlab.ics.muni.cz/muni-kypo-csc/cyber-sandbox-creator # # -*- mode: ruby -*- diff --git a/setup.cfg b/setup.cfg index b24ab3bd8430f1ac28661bf1f862527208816ff7..fc5884359818c36e889ae2739d691e6c9278776c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = sandboxcreator -version = 2.0.0 +version = 2.0.1 author = Attila Farkas, Jana Ziková, Kamil Andoniadis author_email = farkas@mail.muni.cz description = Local virtual lab creation