Example #1
0
def run(target_name, env_name, arguments, dry_run=False):
    target = get_config().targets.get(target_name, None)
    environment = get_config().environments.get(env_name, None)

    if not env_exists():
        log('Virtual environment does not exist.. '
            'Please run: ansible-flow venv create')
        sys.exit(1)

    if not target:
        log('Could not find target: {0}'.format(target_name))
        sys.exit(1)

    if not environment:
        log('Could not find environment: {0}'.format(env_name))
        sys.exit(1)

    for playbook in target.playbooks:
        command = build_ansible_command(playbook, target, environment)
        log(command)

        if not dry_run:
            os_env = {}
            if environment.shell_vars:
                os_env.update(environment.shell_vars)
            if environment.ansible_config:
                os_env.update({'ANSIBLE_CONFIG': environment.ansible_config})

            execute_under_env(command, os_env or None)
Example #2
0
def create_env():
    if env_exists():
        raise Exception('Virtual environment already exists.')

    log('Creating virtual environment...')

    home_dir, lib_dir, inc_dir, bin_dir = venv.path_locations(ENV_PATH)
    python_loc = venv.install_python(
        home_dir,
        lib_dir,
        inc_dir,
        bin_dir,
        site_packages=False,
        clear=False,
        symlink=True
    )

    python_abs_loc = os.path.abspath(python_loc)

    venv.install_activate(home_dir, bin_dir)
    venv.install_wheel(['setuptools', 'pip'], python_abs_loc, None)
    venv.install_distutils(home_dir)

    log('Installing requirements...')
    req_cmd = '{0}/bin/pip install {1}'.format(
        ENV_PATH,
        get_config().requirements
    )
    execute_under_env(req_cmd)

    log('Virtual environment created!')
def create_env():
    if env_exists():
        raise Exception('Virtual environment already exists.')

    log('Creating virtual environment...')

    home_dir, lib_dir, inc_dir, bin_dir = venv.path_locations(ENV_PATH)
    python_loc = venv.install_python(home_dir,
                                     lib_dir,
                                     inc_dir,
                                     bin_dir,
                                     site_packages=False,
                                     clear=False,
                                     symlink=True)

    python_abs_loc = os.path.abspath(python_loc)

    venv.install_activate(home_dir, bin_dir)
    venv.install_wheel(['setuptools', 'pip'], python_abs_loc, None)
    venv.install_distutils(home_dir)

    log('Installing requirements...')
    req_cmd = '{0}/bin/pip install {1}'.format(ENV_PATH,
                                               get_config().requirements)
    execute_under_env(req_cmd)

    log('Virtual environment created!')
Example #4
0
def delete_env():
    shutil.rmtree(ENV_PATH)
    log('Virtual environment deleted!')
Example #5
0
def argument_handler(value, all_args):
    if value is True:
        log('Please specify a target to run...')
        sys.exit(1)

    run(value[0], all_args.env, all_args)
def delete_env():
    shutil.rmtree(ENV_PATH)
    log('Virtual environment deleted!')