Skip to content
Snippets Groups Projects
Commit 741fca1b authored by Attila Farkas's avatar Attila Farkas
Browse files

fix issues with relative path

parent 456fa113
No related branches found
No related tags found
1 merge request!15Resolve "Support Jinja templates in files with extra_vars"
"""This module contains functions to parse input arguments.""" """This module contains functions to parse input arguments."""
import argparse import argparse
import os
def parse_input_args(): def parse_input_args():
...@@ -37,7 +38,10 @@ def parse_input_args(): ...@@ -37,7 +38,10 @@ def parse_input_args():
flags["ansible_local"] = args.ansible_local flags["ansible_local"] = args.ansible_local
flags["verbose_ansible"] = args.verbose_ansible flags["verbose_ansible"] = args.verbose_ansible
flags["border_router"] = args.border_router flags["border_router"] = args.border_router
flags["provisioning_dir"] = args.provisioning_dir flags["target_location"] = "sandbox"
flags["extra_vars"] = args.extra_vars if args.provisioning_dir:
flags["provisioning_dir"] = os.path.abspath(os.path.expanduser(args.provisioning_dir))
if args.extra_vars:
flags["extra_vars"] = os.path.abspath(os.path.expanduser(args.extra_vars))
return input_file_name, flags return input_file_name, flags
"""Contains functions for generating a Vagrantfile from input definitions.""" """Contains functions for generating a Vagrantfile from input definitions."""
import os
from modules.file_manager import generate_file, open_yaml from modules.file_manager import generate_file, open_yaml
VAGRANT_MAPPING = open_yaml("conf/vagrant_mapping.yml") VAGRANT_MAPPING = open_yaml("conf/vagrant_mapping.yml")
...@@ -137,7 +139,8 @@ def _create_ansible_commands(playbook_location, input_definitions, flags): ...@@ -137,7 +139,8 @@ def _create_ansible_commands(playbook_location, input_definitions, flags):
if "ansible_local" in flags and flags["ansible_local"]: if "ansible_local" in flags and flags["ansible_local"]:
extra_vars_location = "/vagrant/extra_vars.yml" extra_vars_location = "/vagrant/extra_vars.yml"
else: else:
extra_vars_location = flags["extra_vars"] extra_vars_location = os.path.relpath(flags["extra_vars"],
flags["target_location"])
user_extra_vars = dict() user_extra_vars = dict()
user_extra_vars["type"] = "string" user_extra_vars["type"] = "string"
user_extra_vars["command"] = "raw_arguments" user_extra_vars["command"] = "raw_arguments"
...@@ -195,8 +198,8 @@ def _call_provisioner(input_definitions, flags): ...@@ -195,8 +198,8 @@ def _call_provisioner(input_definitions, flags):
"""Create entry to vagrant definitions for calling the provisioner.""" """Create entry to vagrant definitions for calling the provisioner."""
provisioner_calls = [] provisioner_calls = []
if "extra_vars" in flags and flags["extra_vars"] and\ if "extra_vars" in flags and flags["extra_vars"] and \
"ansible_local" in flags and flags["ansible_local"]: "ansible_local" in flags and flags["ansible_local"]:
copy_extra_vars = dict() copy_extra_vars = dict()
copy_extra_vars["type"] = "provision" copy_extra_vars["type"] = "provision"
copy_extra_vars["provisioner"] = "file" copy_extra_vars["provisioner"] = "file"
...@@ -205,7 +208,8 @@ def _call_provisioner(input_definitions, flags): ...@@ -205,7 +208,8 @@ def _call_provisioner(input_definitions, flags):
source_arg = dict() source_arg = dict()
source_arg["type"] = "string" source_arg["type"] = "string"
source_arg["command"] = "source" source_arg["command"] = "source"
source_arg["value"] = flags["extra_vars"] source_arg["value"] = os.path.relpath(flags["extra_vars"],
flags["target_location"])
destination_arg = dict() destination_arg = dict()
destination_arg["type"] = "string" destination_arg["type"] = "string"
destination_arg["command"] = "destination" destination_arg["command"] = "destination"
...@@ -213,7 +217,6 @@ def _call_provisioner(input_definitions, flags): ...@@ -213,7 +217,6 @@ def _call_provisioner(input_definitions, flags):
copy_extra_vars["commands"] = [source_arg, destination_arg] copy_extra_vars["commands"] = [source_arg, destination_arg]
provisioner_calls.append(copy_extra_vars) provisioner_calls.append(copy_extra_vars)
config_playbook = dict() config_playbook = dict()
config_playbook["type"] = "provision" config_playbook["type"] = "provision"
if "ansible_local" in flags and flags["ansible_local"]: if "ansible_local" in flags and flags["ansible_local"]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment