Skip to content

Commit

Permalink
Add copy of ansible playbooks to new folder structure (#202)
Browse files Browse the repository at this point in the history
* Item: #58 Desc: Change template to match query parameter from ansible inventory creation

* Item: #58 Desc: Changed list creation to more pythonic way

* Item: #58 Desc: Fix issue with terraform file helper

* Item: #58 Desc: Code refactor and moving code to TerraformRunner class

* Item: #58 Desc: Add waiting for ansible inventory creation

* Item: #58 Desc: Change name of inventory existing variable

* Item: #58 Desc: Fixes with paths to libraries

* Item: #59 Desc: Add initial template to generate new inventory

* Item: #59 Desc: Change ansible inventory to template

* Item: #59 Desc: Refactoring of code

* Item: #59 Desc: Add runner execution

* Item: #59 Desc: Add working ansible runner code

* Item: #59 Desc: Add copy of ansible playbooks
  • Loading branch information
erzetpe authored Apr 8, 2019
1 parent fb43c8b commit 4d708d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
25 changes: 16 additions & 9 deletions core/src/epicli/cli/engine/AnsibleRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

from cli.engine.AnsibleInventoryCreator import AnsibleInventoryCreator
from cli.helpers.Step import Step
from cli.helpers.build_saver import get_inventory_path, get_output_path
from cli.helpers.build_saver import get_inventory_path, get_ansible_path, copy_files_recursively


class AnsibleRunner(Step):

ANSIBLE_PLAYBOOKS_PATH = "/../../../../core/src/ansible/"

def __init__(self, cluster_model, config_docs):
super().__init__(__name__)
self.cluster_model = cluster_model
Expand All @@ -32,20 +35,24 @@ def run(self):
if if_inventory_exists_and_have_content:
continue

inventory = self.inventory_creator.create()
self.inventory_creator.create()
time.sleep(10)

src = os.path.dirname(__file__) + AnsibleRunner.ANSIBLE_PLAYBOOKS_PATH

copy_files_recursively(src, get_ansible_path(self.cluster_model.specification.name))

# todo run ansible playbooks
for i in range(30):
runner = ansible_runner.run(private_data_dir=get_output_path(), host_pattern="all",
for i in range(10):
runner = ansible_runner.run(private_data_dir=get_ansible_path(self.cluster_model.specification.name), host_pattern="all",
inventory=inventory_path,
module='raw', module_args='sudo apt-get install -y python-simplejson')

if runner.status == "successful":
continue
print(runner.status)
if runner.status.lower() == "successful":
break

time.sleep(10)
ansible_runner.run(private_data_dir=get_output_path(), host_pattern="all",

ansible_runner.run(private_data_dir=get_ansible_path(self.cluster_model.specification.name), host_pattern="all",
inventory=inventory_path,
module='shell', module_args='whoami')
13 changes: 13 additions & 0 deletions core/src/epicli/cli/helpers/build_saver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import distutils
import os
from cli.helpers.data_loader import load_template_file, types
from cli.helpers.yaml_helpers import dump_all
Expand All @@ -7,6 +8,7 @@
TERRAFORM_OUTPUT_DIR = 'terraform/'
MANIFEST_FILE_NAME = 'manifest.yml'
INVENTORY_FILE_NAME = 'inventory'
ANSIBLE_OUTPUT_DIR = 'ansible/'


def save_manifest(docs, cluster_name):
Expand Down Expand Up @@ -58,3 +60,14 @@ def get_terraform_path(cluster_name):
if not os.path.exists(terraform_dir):
os.makedirs(terraform_dir)
return terraform_dir


def get_ansible_path(cluster_name):
ansible_dir = os.path.join(get_build_path(cluster_name), ANSIBLE_OUTPUT_DIR)
if not os.path.exists(ansible_dir):
os.makedirs(ansible_dir)
return ansible_dir


def copy_files_recursively(src, dst):
distutils.dir_util.copy_tree(src, dst)

0 comments on commit 4d708d3

Please sign in to comment.