How to use the molecule.util.abs_path function in molecule

To help you get started, we’ve selected a few molecule examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / molecule / test / unit / test_config.py View on Github external
def test_env_file_property(config_instance):
    config_instance.args = {'env_file': '.env'}
    result = config_instance.env_file

    assert util.abs_path(config_instance.args.get('env_file')) == result
github ansible / molecule / test / unit / test_util.py View on Github external
def test_abs_path_with_none_path():
    assert util.abs_path(None) is None
github ansible / molecule / molecule / command / init / scenario.py View on Github external
def execute(self):
        """
        Execute the actions necessary to perform a `molecule init scenario` and
        returns None.

        :return: None
        """
        scenario_name = self._command_args['scenario_name']
        role_name = os.getcwd().split(os.sep)[-1]
        role_directory = util.abs_path(os.path.join(os.getcwd(), os.pardir))

        msg = 'Initializing new scenario {}...'.format(scenario_name)
        LOG.info(msg)
        molecule_directory = config.molecule_directory(
            os.path.join(role_directory, role_name)
        )
        scenario_directory = os.path.join(molecule_directory, scenario_name)

        if os.path.isdir(scenario_directory):
            msg = (
                'The directory molecule/{} exists. ' 'Cannot create new scenario.'
            ).format(scenario_name)
            util.sysexit_with_message(msg)

        driver_template = api.drivers()[
            self._command_args['driver_name']
github ansible / molecule / molecule / command / init.py View on Github external
def _init_new_scenario(command_args):
    """
    Initialize a new scenario:

    >>> molecule init scenario --scenario-name default --role-name foo
    """
    scenario_name = command_args['scenario_name']
    role_name = os.getcwd().split(os.sep)[-1]
    role_directory = util.abs_path(os.path.join(os.getcwd(), os.pardir))

    LOG.info('Initializing new scenario {}...'.format(scenario_name))
    molecule_directory = config.molecule_directory(
        os.path.join(role_directory, role_name))
    scenario_directory = os.path.join(molecule_directory, scenario_name)
    scenario_base_directory = os.path.dirname(scenario_directory)

    if os.path.isdir(scenario_directory):
        msg = ('The directory molecule/{} exists. '
               'Cannot create new scenario.').format(scenario_name)
        util.sysexit_with_message(msg)

    scenario_base_directory = os.path.join(role_directory, role_name)
    templates = [
        'scenario/driver/{driver_name}'.format(**command_args),
        'scenario/verifier/{verifier_name}'.format(**command_args),
github ansible / molecule / molecule / provisioner / ansible_playbooks.py View on Github external
def _get_playbook_directory(self):
        return util.abs_path(
            os.path.join(self._config.provisioner.directory, 'playbooks')
        )
github ansible / molecule / molecule / command / base.py View on Github external
def get_configs(args, command_args, ansible_args=()):
    """
    Glob the current directory for Molecule config files, instantiate config
    objects, and returns a list.

    :param args: A dict of options, arguments and commands from the CLI.
    :param command_args: A dict of options passed to the subcommand from
     the CLI.
    :param ansible_args: An optional tuple of arguments provided to the
     `ansible-playbook` command.
    :return: list
    """
    configs = [
        config.Config(
            molecule_file=util.abs_path(c),
            args=args,
            command_args=command_args,
            ansible_args=ansible_args,
        )
        for c in glob.glob(MOLECULE_GLOB)
    ]
    _verify_configs(configs)

    return configs
github ansible / molecule / molecule / provisioner / ansible.py View on Github external
def abs_path(self, path):
        return util.abs_path(os.path.join(self._config.scenario.directory, path))