Skip to content

Commit

Permalink
Refactoring of ansible code (#199)
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
  • Loading branch information
erzetpe authored Apr 5, 2019
1 parent 8d01a69 commit aeb0270
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions core/src/epicli/cli/helpers/build_saver.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

from cli.helpers.data_loader import load_template_file
from cli.helpers.yaml_helpers import dump_all

from cli.helpers import data_types
from cli.helpers.data_loader import load_template_file
from cli.helpers.yaml_helpers import dump_all

OUTPUT_FOLDER_PATH = '../../output/'
TERRAFORM_OUTPUT_DIR = 'terraform/'
Expand All @@ -19,19 +21,21 @@ def save_manifest(docs, cluster_name):
def save_inventory(inventory, cluster_model):
cluster_name = cluster_model.specification.name
build_dir = get_build_path(cluster_name)

template = load_template_file("ansible", "common", "ansible_inventory")

template = load_template_file(data_types.ANSIBLE, "common", "ansible_inventory")
content = template.render(inventory=inventory, cluster_model=cluster_model)

with open(os.path.join(build_dir, INVENTORY_FILE_NAME), 'w') as file:
file.write(content)
file_path = os.path.join(build_dir, INVENTORY_FILE_NAME)
save_to_file(file_path, content)


def save_terraform_file(content, cluster_name, filename):
terraform_dir = get_terraform_path(cluster_name)
with open(os.path.join(terraform_dir, filename), 'w') as terraform_output_file:
terraform_output_file.write(content)
terraform_output_file_path = os.path.join(terraform_dir, filename)
save_to_file(terraform_output_file_path, content)


def save_to_file(file_path, content):
with open(file_path, 'w') as file:
file.write(content)


def get_output_path():
Expand Down
1 change: 1 addition & 0 deletions core/src/epicli/cli/helpers/data_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEFAULT = 'defaults'
VALIDATION = 'validation'
TERRAFORM = 'terraform'
ANSIBLE = 'ansible'

0 comments on commit aeb0270

Please sign in to comment.