Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Jul 4, 2022
1 parent a6a83de commit 83d0d13
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions VirtualMachineService/ancon/Playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class Playbook(object):
PLAYBOOK_FAILED = "PLAYBOOK_FAILED"

def __init__(
self,
ip,
port,
playbooks_information,
osi_private_key,
public_key,
pool,
loaded_metadata_keys,
cloud_site,
self,
ip,
port,
playbooks_information,
osi_private_key,
public_key,
pool,
loaded_metadata_keys,
cloud_site,
):
self.loaded_metadata_keys = loaded_metadata_keys
self.cloud_site = cloud_site
Expand All @@ -57,8 +57,6 @@ def __init__(
)
self.returncode = -1
self.playbooks_information = playbooks_information
LOG.exception(self.playbooks_information)

self.stdout = ""
self.stderr = ""
# init temporary directories and mandatory generic files
Expand All @@ -72,10 +70,10 @@ def __init__(
self.private_key.close()

self.log_file_stdout = NamedTemporaryFile(
mode="w+", dir=self.directory.name, delete=False,prefix="log_stdout"
mode="w+", dir=self.directory.name, delete=False, prefix="log_stdout"
)
self.log_file_stderr = NamedTemporaryFile(
mode="w+", dir=self.directory.name, delete=False,prefix="log_err"
mode="w+", dir=self.directory.name, delete=False, prefix="log_err"
)

# create the custom playbook and save its name
Expand All @@ -84,7 +82,7 @@ def __init__(

# create inventory
self.inventory = NamedTemporaryFile(
mode="w+", dir=self.directory.name, delete=False,prefix="inventory_"
mode="w+", dir=self.directory.name, delete=False, prefix="inventory_"
)

inventory_string = (
Expand All @@ -106,12 +104,12 @@ def copy_playbooks_and_init(self, playbooks_information, public_key):
self.playbooks_dir + "/change_key_vars_file.yml", self.directory.name
)
with open(
self.directory.name + "/change_key_vars_file.yml", mode="r"
self.directory.name + "/change_key_vars_file.yml", mode="r"
) as key_file:
data_ck = self.yaml_exec.load(key_file)
data_ck["change_key_vars"]["key"] = public_key.strip('"')
with open(
self.directory.name + "/change_key_vars_file.yml", mode="w"
self.directory.name + "/change_key_vars_file.yml", mode="w"
) as key_file:
self.yaml_exec.dump(data_ck, key_file)
self.add_to_playbook_always_lists("change_key")
Expand All @@ -121,19 +119,21 @@ def copy_playbooks_and_init(self, playbooks_information, public_key):
self.playbooks_dir + "/" + self.playbook_exec_name, self.directory.name
)
with open(
self.directory.name + "/" + self.playbook_exec_name, mode="r"
self.directory.name + "/" + self.playbook_exec_name, mode="r"
) as generic_playbook:
data_gp = self.yaml_exec.load(generic_playbook)
data_gp[0]["vars_files"] = self.vars_files
data_gp[0]["tasks"][0]["block"] = self.tasks
data_gp[0]["tasks"][0]["always"] = self.always_tasks
with open(
self.directory.name + "/" + self.playbook_exec_name, mode="w"
self.directory.name + "/" + self.playbook_exec_name, mode="w"
) as generic_playbook:
self.yaml_exec.dump(data_gp, generic_playbook)

def copy_and_init(self, playbook_name, playbook_vars):
def load_vars():
LOG.info(f"Playbook vars: {playbook_vars}")

if playbook_name == CONDA:
for k, v in playbook_vars.items():
if k == "packages":
Expand All @@ -146,24 +146,24 @@ def load_vars():
data[playbook_name + "_vars"][k] = p_dict
if playbook_name in self.loaded_metadata_keys:
for k, v in playbook_vars.items():
LOG.info(playbook_vars)
if k == "template_version":
data[playbook_name + "_vars"][k] = v
if k == "create_only_backend":
if data[playbook_name + "_vars"][k] in ["false", "False"]:
elif k == "create_only_backend":
create_only_backend = data[playbook_name + "_vars"][k]
if create_only_backend in ["false", "False"]:
data[playbook_name + "_vars"][k] = False
elif data[playbook_name + "_vars"][k] in ["true", "True"]:
elif create_only_backend in ["true", "True"]:
data[playbook_name + "_vars"][k] = True

if k == "base_url":
elif k == "base_url":
data[playbook_name + "_vars"][k] = v

if playbook_name == OPTIONAL:
for k, v in playbook_vars.items():
if k == MOSH:
data[playbook_name + "_defined"][k] = v

LOG.info(f"fPlaybook Data - {data}")
LOG.info(f"Playbook Data - {data}")

# copy whole directory
shutil.copytree(
Expand All @@ -176,7 +176,7 @@ def load_vars():
playbook_name_local = playbook_name
if os.path.isfile(self.directory.name + site_specific_yml):
playbook_name_local = playbook_name + "-" + self.cloud_site
original_playbook_var_yml=f"{self.playbooks_dir}/{playbook_name}/{playbook_name}_vars_file.yml"
original_playbook_var_yml = f"{self.playbooks_dir}/{playbook_name}/{playbook_name}_vars_file.yml"
playbook_var_yml = f"/{playbook_name}_vars_file.yml"
LOG.info("Remove copy of vars file")
os.remove(self.directory.name + playbook_var_yml)
Expand Down

0 comments on commit 83d0d13

Please sign in to comment.