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

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
vktrrdk committed Oct 24, 2019
2 parents cd931e4 + ef3668e commit e39600d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions VirtualMachineService/ancon/Playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions VirtualMachineService/ancon/playbooks/generic_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
gather_facts: yes
vars_files:
tasks:
- name: Setting up your virtual machine
block:
always:
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e39600d

Please sign in to comment.