diff --git a/VirtualMachineService/ancon/Playbook.py b/VirtualMachineService/ancon/Playbook.py index 66ab2247..1763d074 100644 --- a/VirtualMachineService/ancon/Playbook.py +++ b/VirtualMachineService/ancon/Playbook.py @@ -20,6 +20,7 @@ def __init__(self, ip, port, playbooks_information, osi_private_key, public_key, self.yaml_exec = ruamel.yaml.YAML() self.vars_files = [] self.tasks = [] + self.always_tasks = [] self.logger = logger self.process = None self.returncode = -1 @@ -43,7 +44,8 @@ def __init__(self, ip, port, playbooks_information, osi_private_key, public_key, # create inventory self.inventory = NamedTemporaryFile(mode="w+", dir=self.directory.name, delete=False) inventory_string = "[vm]\n" + ip + ":" + port + " ansible_user=ubuntu " \ - "ansible_ssh_private_key_file=" + self.private_key.name + "ansible_ssh_private_key_file=" + self.private_key.name \ + + " ansible_python_interpreter=/usr/bin/python3" self.inventory.write(inventory_string) self.inventory.close() @@ -60,14 +62,15 @@ def copy_playbooks_and_init(self, playbooks_information, public_key): data_ck["change_key_vars"]["key"] = public_key.strip('\"') with open(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_lists("change_key") + self.add_to_playbook_always_lists("change_key") # write all vars_files and tasks in generic_playbook shutil.copy(self.playbooks_dir + "/" + self.playbook_exec_name, self.directory.name) with open(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"] = self.tasks + 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') as generic_playbook: self.yaml_exec.dump(data_gp, generic_playbook) @@ -131,6 +134,13 @@ def add_to_playbook_lists(self, playbook_name): def add_tasks_only(self, playbook_name): self.tasks.append(dict(name="Running {0} tasks".format(playbook_name), import_tasks=playbook_name+".yml")) + def add_to_playbook_always_lists(self, playbook_name): + self.vars_files.append(playbook_name + "_vars_file.yml") + self.always_tasks.append(dict(name="Running {0} tasks".format(playbook_name), import_tasks=playbook_name+".yml")) + + def add_always_tasks_only(self, playbook_name): + self.always_tasks.append(dict(name="Running {0} tasks".format(playbook_name), import_tasks=playbook_name+".yml")) + def run_it(self): command_string = "/usr/local/bin/ansible-playbook -v -i {0} {1}/{2}"\ .format(self.inventory.name, self.directory.name, self.playbook_exec_name) diff --git a/VirtualMachineService/ancon/playbooks/bioconda_vars_file.yml b/VirtualMachineService/ancon/playbooks/bioconda_vars_file.yml index 980b3557..ad1e7fd7 100644 --- a/VirtualMachineService/ancon/playbooks/bioconda_vars_file.yml +++ b/VirtualMachineService/ancon/playbooks/bioconda_vars_file.yml @@ -6,4 +6,4 @@ bioconda_tools: bioconda_folders: install_script: "/home/{{ ansible_user_id }}/install_miniconda3.sh" conda_dir: "/home/{{ ansible_user_id }}/miniconda3" - conda_installer_url: "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" + conda_installer_url: "https://repo.anaconda.com/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh" diff --git a/VirtualMachineService/ancon/playbooks/generic_playbook.yml b/VirtualMachineService/ancon/playbooks/generic_playbook.yml index bea7831f..356b056f 100644 --- a/VirtualMachineService/ancon/playbooks/generic_playbook.yml +++ b/VirtualMachineService/ancon/playbooks/generic_playbook.yml @@ -4,3 +4,6 @@ gather_facts: yes vars_files: tasks: + - name: Setting up your virtual machine + block: + always: diff --git a/requirements.txt b/requirements.txt index fc0f1a4e..299b89de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ openstacksdk ==0.27.0 deprecated == 1.2.4 Click==7.0 flake8==3.7.7 -ansible==2.8.0 +ansible==2.7.14 ruamel.yaml<0.16.00 paramiko==2.6.0 pyvim==2.0.24