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)
def intersect_limits(args_limit, cli_limit): """Create an Ansible host pattern of the intersection of two patterns. :param args_limit: user-specified limit, or None. :param cli_limit: limit originating from this CLI, or None. :returns: a string representing an intersection of the two patterns. """ # NOTE(mgoddard): Ansible uses either commas (,) or colons (:) to separate # parts of a host pattern. An intersection is specified using a separator # followed by an ampersand (&). If a mix of comma and colon separators is # used, Ansible picks one and treats the other as part of the host pattern. # This leads to hard to diagnose errors. Try to determine which separator # the user has specified, and be consistent. Error if both are used. if args_limit and ',' in args_limit: if ':' in args_limit: raise exception.Error("Invalid format for host limit argument. " "Cannot mix commas and colons to separate " "hosts") separator = ',&' else: separator = ':&' limits = [l for l in [args_limit, cli_limit] if l] return separator.join(limits)