示例#1
0
def _get_environment(parsed_args):
    """Return an environment dict for executing Kolla Ansible."""
    env = os.environ.copy()
    vault.update_environment(parsed_args, env)
    # If a custom Ansible configuration file exists, use it. Allow
    # etc/kayobe/kolla/ansible.cfg or etc/kayobe/ansible.cfg.
    ansible_cfg_path = os.path.join(parsed_args.config_path, "kolla",
                                    "ansible.cfg")
    if utils.is_readable_file(ansible_cfg_path)["result"]:
        env.setdefault("ANSIBLE_CONFIG", ansible_cfg_path)
    else:
        ansible_cfg_path = os.path.join(parsed_args.config_path, "ansible.cfg")
        if utils.is_readable_file(ansible_cfg_path)["result"]:
            env.setdefault("ANSIBLE_CONFIG", ansible_cfg_path)
    return env
示例#2
0
def _validate_args(parsed_args, inventory_filename):
    """Validate Kayobe Ansible arguments."""
    vault.validate_args(parsed_args)
    result = utils.is_readable_dir(parsed_args.kolla_config_path)
    if not result["result"]:
        LOG.error("Kolla configuration path %s is invalid: %s",
                  parsed_args.kolla_config_path, result["message"])
        sys.exit(1)

    inventory = _get_inventory_path(parsed_args, inventory_filename)
    result = utils.is_readable_dir(parsed_args.kolla_venv)
    if not result["result"]:
        # NOTE(mgoddard): Previously the inventory was a file, now it is a
        # directory to allow us to support inventory host_vars. Support both
        # formats for now.
        result_f = utils.is_readable_file(inventory)
        if not result_f["result"]:
            LOG.error("Kolla inventory %s is invalid: %s", inventory,
                      result["message"])
            sys.exit(1)

    result = utils.is_readable_dir(parsed_args.kolla_venv)
    if not result["result"]:
        LOG.error("Kolla virtualenv %s is invalid: %s", parsed_args.kolla_venv,
                  result["message"])
        sys.exit(1)
示例#3
0
def install_galaxy_roles(parsed_args, force=False):
    """Install Ansible Galaxy role dependencies.

    Installs dependencies specified in kayobe, and if present, in kayobe
    configuration.

    :param parsed_args: Parsed command line arguments.
    :param force: Whether to force reinstallation of roles.
    """
    LOG.info("Installing galaxy role dependencies from kayobe")
    requirements = utils.get_data_files_path("requirements.yml")
    roles_destination = utils.get_data_files_path('ansible', 'roles')
    utils.galaxy_install(requirements, roles_destination, force=force)

    # Check for requirements in kayobe configuration.
    kc_reqs_path = os.path.join(parsed_args.config_path, "ansible",
                                "requirements.yml")
    if not utils.is_readable_file(kc_reqs_path)["result"]:
        LOG.info("Not installing galaxy role dependencies from kayobe config "
                 "- requirements.yml not present")
        return

    LOG.info("Installing galaxy role dependencies from kayobe config")
    # Ensure a roles directory exists in kayobe-config.
    kc_roles_path = os.path.join(parsed_args.config_path, "ansible", "roles")
    try:
        os.makedirs(kc_roles_path)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise exception.Error("Failed to create directory ansible/roles/ "
                                  "in kayobe configuration at %s: %s" %
                                  (parsed_args.config_path, str(e)))

    # Install roles from kayobe-config.
    utils.galaxy_install(kc_reqs_path, kc_roles_path, force=force)
示例#4
0
def _validate_args(parsed_args, playbooks):
    """Validate Kayobe Ansible arguments."""
    vault.validate_args(parsed_args)
    result = utils.is_readable_dir(parsed_args.config_path)
    if not result["result"]:
        LOG.error("Kayobe configuration path %s is invalid: %s",
                  parsed_args.config_path, result["message"])
        sys.exit(1)

    env_path = _get_kayobe_environment_path(parsed_args)
    if env_path:
        result = utils.is_readable_dir(env_path)
        if not result["result"]:
            LOG.error("Kayobe environment %s is invalid: %s", env_path,
                      result["message"])
            sys.exit(1)

    inventories = _get_inventories_paths(parsed_args, env_path)
    for inventory in inventories:
        result = utils.is_readable_dir(inventory)
        if not result["result"]:
            LOG.error("Kayobe inventory %s is invalid: %s", inventory,
                      result["message"])
            sys.exit(1)

    for playbook in playbooks:
        result = utils.is_readable_file(playbook)
        if not result["result"]:
            LOG.error("Kayobe playbook %s is invalid: %s", playbook,
                      result["message"])
            sys.exit(1)
示例#5
0
def _get_vars_files(config_path):
    """Return a list of Kayobe Ansible configuration variable files."""
    vars_files = []
    for vars_file in os.listdir(config_path):
        abs_path = os.path.join(config_path, vars_file)
        if utils.is_readable_file(abs_path):
            root, ext = os.path.splitext(vars_file)
            if ext in (".yml", ".yaml", ".json"):
                vars_files.append(abs_path)
    return vars_files
示例#6
0
文件: ansible.py 项目: pforai/kayobe
def _get_vars_files(config_path):
    """Return a list of Kayobe Ansible configuration variable files."""
    vars_files = []
    for vars_file in os.listdir(config_path):
        abs_path = os.path.join(config_path, vars_file)
        if utils.is_readable_file(abs_path):
            root, ext = os.path.splitext(vars_file)
            if ext in (".yml", ".yaml", ".json"):
                vars_files.append(abs_path)
    return vars_files
示例#7
0
def _get_vars_files(config_path):
    """Return a list of Kayobe Ansible configuration variable files.

    The files will be sorted alphabetically by name.
    """
    vars_files = []
    for vars_file in os.listdir(config_path):
        abs_path = os.path.join(config_path, vars_file)
        if utils.is_readable_file(abs_path)["result"]:
            root, ext = os.path.splitext(vars_file)
            if ext in (".yml", ".yaml", ".json"):
                vars_files.append(abs_path)
    return sorted(vars_files)
示例#8
0
def _get_environment(parsed_args):
    """Return an environment dict for executing an Ansible playbook."""
    env = os.environ.copy()
    vault.update_environment(parsed_args, env)
    # If the configuration path has been specified via --config-path, ensure
    # the environment variable is set, so that it can be referenced by
    # playbooks.
    env.setdefault(CONFIG_PATH_ENV, parsed_args.config_path)
    # If a custom Ansible configuration file exists, use it.
    ansible_cfg_path = os.path.join(parsed_args.config_path, "ansible.cfg")
    if utils.is_readable_file(ansible_cfg_path)["result"]:
        env.setdefault("ANSIBLE_CONFIG", ansible_cfg_path)
    return env
示例#9
0
def _get_environment(parsed_args):
    """Return an environment dict for executing Kolla Ansible."""
    env = os.environ.copy()
    vault.update_environment(parsed_args, env)
    # If a custom Ansible configuration file exists, use it. Allow
    # etc/kayobe/kolla/ansible.cfg or etc/kayobe/ansible.cfg.
    ansible_cfg_path = os.path.join(parsed_args.config_path, "kolla",
                                    "ansible.cfg")
    if utils.is_readable_file(ansible_cfg_path)["result"]:
        env.setdefault("ANSIBLE_CONFIG", ansible_cfg_path)
    else:
        ansible_cfg_path = os.path.join(parsed_args.config_path, "ansible.cfg")
        if utils.is_readable_file(ansible_cfg_path)["result"]:
            env.setdefault("ANSIBLE_CONFIG", ansible_cfg_path)
    # kolla-ansible allows passing additional arguments to ansible-playbook via
    # EXTRA_OPTS.
    if parsed_args.check or parsed_args.diff:
        extra_opts = env.setdefault("EXTRA_OPTS", "")
        if parsed_args.check and "--check" not in extra_opts:
            env["EXTRA_OPTS"] += " --check"
        if parsed_args.diff and "--diff" not in extra_opts:
            env["EXTRA_OPTS"] += " --diff"
    return env
示例#10
0
def _get_vars_files(vars_paths):
    """Return a list of Kayobe Ansible configuration variable files.

    The list of directories given as argument is searched to create the list of
    variable files. The files will be sorted alphabetically by name for each
    directory, but ordering of directories is kept to allow overrides.
    """
    vars_files = []
    for vars_path in vars_paths:
        path_vars_files = []
        for vars_file in os.listdir(vars_path):
            abs_path = os.path.join(vars_path, vars_file)
            if utils.is_readable_file(abs_path)["result"]:
                root, ext = os.path.splitext(vars_file)
                if ext in (".yml", ".yaml", ".json"):
                    path_vars_files.append(abs_path)
        vars_files += sorted(path_vars_files)

    return vars_files
示例#11
0
def _validate_args(parsed_args, inventory_filename):
    """Validate Kayobe Ansible arguments."""
    result = utils.is_readable_dir(parsed_args.kolla_config_path)
    if not result["result"]:
        LOG.error("Kolla configuration path %s is invalid: %s",
                  parsed_args.kolla_config_path, result["message"])
        sys.exit(1)

    inventory = _get_inventory_path(parsed_args, inventory_filename)
    result = utils.is_readable_file(inventory)
    if not result["result"]:
        LOG.error("Kolla inventory %s is invalid: %s", inventory,
                  result["message"])
        sys.exit(1)

    result = utils.is_readable_dir(parsed_args.kolla_venv)
    if not result["result"]:
        LOG.error("Kolla virtualenv %s is invalid: %s", parsed_args.kolla_venv,
                  result["message"])
        sys.exit(1)
示例#12
0
def _validate_args(parsed_args, inventory_filename):
    """Validate Kayobe Ansible arguments."""
    result = utils.is_readable_dir(parsed_args.kolla_config_path)
    if not result["result"]:
        LOG.error("Kolla configuration path %s is invalid: %s",
                  parsed_args.kolla_config_path, result["message"])
        sys.exit(1)

    inventory = _get_inventory_path(parsed_args, inventory_filename)
    result = utils.is_readable_file(inventory)
    if not result["result"]:
        LOG.error("Kolla inventory %s is invalid: %s",
                  inventory, result["message"])
        sys.exit(1)

    result = utils.is_readable_dir(parsed_args.kolla_venv)
    if not result["result"]:
        LOG.error("Kolla virtualenv %s is invalid: %s",
                  parsed_args.kolla_venv, result["message"])
        sys.exit(1)
示例#13
0
def _validate_args(parsed_args, playbooks):
    """Validate Kayobe Ansible arguments."""
    result = utils.is_readable_dir(parsed_args.config_path)
    if not result["result"]:
        LOG.error("Kayobe configuration path %s is invalid: %s",
                  parsed_args.config_path, result["message"])
        sys.exit(1)

    inventory = _get_inventory_path(parsed_args)
    result = utils.is_readable_dir(inventory)
    if not result["result"]:
        LOG.error("Kayobe inventory %s is invalid: %s", inventory,
                  result["message"])
        sys.exit(1)

    for playbook in playbooks:
        result = utils.is_readable_file(playbook)
        if not result["result"]:
            LOG.error("Kayobe playbook %s is invalid: %s", playbook,
                      result["message"])
            sys.exit(1)
示例#14
0
文件: ansible.py 项目: pforai/kayobe
def _validate_args(parsed_args, playbooks):
    """Validate Kayobe Ansible arguments."""
    result = utils.is_readable_dir(parsed_args.config_path)
    if not result["result"]:
        LOG.error("Kayobe configuration path %s is invalid: %s",
                  parsed_args.config_path, result["message"])
        sys.exit(1)

    inventory = _get_inventory_path(parsed_args)
    result = utils.is_readable_dir(inventory)
    if not result["result"]:
        LOG.error("Kayobe inventory %s is invalid: %s",
                  inventory, result["message"])
        sys.exit(1)

    for playbook in playbooks:
        result = utils.is_readable_file(playbook)
        if not result["result"]:
            LOG.error("Kayobe playbook %s is invalid: %s",
                      playbook, result["message"])
            sys.exit(1)
示例#15
0
def passwords_yml_exists(parsed_args):
    """Return whether passwords.yml exists in the kayobe configuration."""
    passwords_path = os.path.join(parsed_args.config_path, 'kolla',
                                  'passwords.yml')
    return utils.is_readable_file(passwords_path)["result"]
示例#16
0
def passwords_yml_exists(parsed_args):
    """Return whether passwords.yml exists in the kayobe configuration."""
    env_path = _get_kayobe_environment_path(parsed_args)
    path = env_path if env_path else parsed_args.config_path
    passwords_path = os.path.join(path, 'kolla', 'passwords.yml')
    return utils.is_readable_file(passwords_path)["result"]