Beispiel #1
0
    def _do_command(self):
        if self.options.filter:
            regexp = re.compile(self.options.filter)
        else:
            regexp = None

        for fact, desc in utilities.iteritems(FACT_DOCS):
            if not regexp or regexp.match(fact):
                print(fact, '-', desc)
Beispiel #2
0
def process_karaf_home(fact_names, host_vars):
    """Process karaf_home indicators to detect Fuse-on-Karaf."""

    if (JBOSS_FUSE_ON_KARAF_KARAF_HOME not in fact_names and
            JBOSS_FUSE_SUMMARY not in fact_names):  # noqa
        return {}

    if 'karaf_homes' not in host_vars:
        return {JBOSS_FUSE_ON_KARAF_KARAF_HOME:
                'Error: fact karaf_homes not collected.'}
    karaf_homes = host_vars['karaf_homes']

    err, bin_fuse = raw_output_present(fact_names, host_vars,
                                       JBOSS_FUSE_ON_KARAF_KARAF_HOME,
                                       'karaf_home_bin_fuse',
                                       'ls -1 KARAF_HOME/bin/fuse')
    if err is not None:
        return err

    err, system_org_jboss = raw_output_present(
        fact_names, host_vars,
        JBOSS_FUSE_ON_KARAF_KARAF_HOME,
        'karaf_home_system_org_jboss',
        'ls -1 KARAF_HOME/system/org/jboss')
    if err is not None:
        return err

    system_org_jboss_results, system_org_jboss_mr = process_indicator_files(
        ['fuse'], system_org_jboss)

    bin_fuse_mr = dict((result['item'], result['rc'] == 0)
                       for i, result in enumerate(bin_fuse['results']))

    bin_fuse_results = dict((directory,
                             '/bin/fuse exists' if result
                             else '/bin/fuse not found')
                            for directory, result
                            in utilities.iteritems(bin_fuse_mr))

    assert list(system_org_jboss_results.keys()) == karaf_homes
    assert list(bin_fuse_results.keys()) == karaf_homes

    fuse_on_karaf_dirs = [u'{0}: {1}; {2}'.format(
        karaf_home,
        bin_fuse_results[karaf_home],
        system_org_jboss_results[karaf_home])
                          for karaf_home in karaf_homes]  # noqa E126
    karaf_home_dict = dict((karaf_home, (system_org_jboss_mr[karaf_home] or
                                         bin_fuse_mr[karaf_home]))
                           for i, karaf_home in enumerate(karaf_homes))
    return {JBOSS_FUSE_ON_KARAF_KARAF_HOME:
            encode_and_join('; ', fuse_on_karaf_dirs),
            JBOSS_FUSE_ON_KARAF_KARAF_HOME + MR: karaf_home_dict}  # noqa
Beispiel #3
0
def log_yaml_inventory(label, inventory):
    """Log yaml inventory but mask passwords

    :param inventory: A dictionary of the ansible inventory
    """
    alpha = inventory.get('alpha')
    hosts_dict = alpha.get('hosts')
    vars_dict = alpha.get('vars')
    redact_key_list = ['ansible_become_pass', 'ansible_ssh_pass']

    # pylint: disable=unused-variable
    for host, host_dict in iteritems(hosts_dict):
        host_dict = redact_dict(redact_key_list, host_dict)

    vars_dict = redact_dict(redact_key_list, vars_dict)

    log.debug('%s:\n%s', label, yaml.dump(inventory))
    return inventory
Beispiel #4
0
def _create_hosts_auths_file(success_auth_map, profile):
    host_auth_mapping = profile + PROFILE_HOST_AUTH_MAPPING_SUFFIX
    host_auth_mapping_path = utilities.get_config_path(host_auth_mapping)
    with open(host_auth_mapping_path, 'a') as host_auth_file:
        string_to_write = time.strftime("%c") + '\n-' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---' \
                                                '---\n'
        for host, line in iteritems(success_auth_map):
            string_to_write += host + '\n----------------------\n'
            for auth in line:
                string_to_write += redacted_auth_string(auth)
            string_to_write += '\n\n'
        string_to_write += '\n*******************************' \
                           '*********************************' \
                           '**************\n\n'
        host_auth_file.write(string_to_write)
Beispiel #5
0
def process_host_vars(facts_to_collect, vars_by_host):
    """Process Ansible output into output facts.

    :param facts_to_collect: list of facts to collect.
    :param vars_by_host: dictionary (host: facts dictionary)
    :returns: list of per host fact dicitionaries
    """
    facts_out = []
    for _, host_vars in utilities.iteritems(vars_by_host):
        this_host = {}

        try:
            this_host.update(host_vars.get('connection', {}))
            this_host.update(host_vars.get('cpu', {}))
            this_host.update(host_vars.get('date', {}))
            this_host.update(host_vars.get('dmi', {}))
            this_host.update(host_vars.get('etc_release', {}))
            this_host.update(host_vars.get('file_contents', {}))
            this_host.update(host_vars.get('redhat_packages', {}))
            this_host.update(host_vars.get('redhat_release', {}))
            this_host.update(host_vars.get('subman', {}))
            this_host.update(host_vars.get('uname', {}))
            this_host.update(host_vars.get('virt', {}))
            this_host.update(host_vars.get('virt_what', {}))

            this_host.update(
                postprocessing.process_jboss_versions(facts_to_collect,
                                                      host_vars))
            this_host.update(
                postprocessing.process_addon_versions(facts_to_collect,
                                                      host_vars))
            this_host.update(
                postprocessing.process_id_u_jboss(facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_common_files(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_processes(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_packages(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_locate(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_init_files(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_jboss_eap_home(facts_to_collect,
                                                      host_vars))
            this_host.update(
                postprocessing.process_fuse_on_eap(facts_to_collect,
                                                   host_vars))
            this_host.update(
                postprocessing.process_karaf_home(facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_fuse_init_files(facts_to_collect,
                                                       host_vars))
            this_host.update(
                postprocessing.process_brms_output(facts_to_collect,
                                                   host_vars))
            this_host.update(
                postprocessing.process_find_jboss_modules_jar(
                    facts_to_collect, host_vars))
            this_host.update(
                postprocessing.process_find_karaf_jar(facts_to_collect,
                                                      host_vars))

            postprocessing.handle_systemid(facts_to_collect, this_host)
            postprocessing.handle_redhat_packages(facts_to_collect, this_host)
            postprocessing.escape_characters(this_host)
            this_host.update(
                postprocessing.generate_eap_summary(facts_to_collect,
                                                    this_host))
            this_host.update(
                postprocessing.generate_fuse_summary(facts_to_collect,
                                                     this_host))

            # After all of the facts have been generated, remove -mr facts
            # which were for machine use only.
            keys = list(this_host.keys())
            for key in keys:
                if key[-3:] == '-mr':
                    del this_host[key]

            facts_out.append(this_host)
        except Exception as processing_error:  # pylint: disable=broad-except
            utilities.log.error('Error during processing.')
            utilities.log.exception(processing_error)

    return facts_out
Beispiel #6
0
def process_brms_output(fact_names, host_vars):
    """Process facts for jboss.brms."""

    business_central_candidates = host_vars.get(
        'business_central_candidates', [])
    kie_server_candidates = host_vars.get(
        'kie_server_candidates', [])

    err, manifest_mf_out = raw_output_present(
        fact_names, host_vars,
        JBOSS_BRMS,
        'jboss_brms_manifest_mf',
        'cat {{ base_directory }}/META-INF/MANIFEST.MF')
    if err is not None:
        return err

    err, kie_in_business_central_out = raw_output_present(
        fact_names, host_vars,
        JBOSS_BRMS,
        'jboss_brms_kie_in_business_central',
        'ls -1 {{ base_directory }}/WEB-INF/lib/kie-api*')
    if err is not None:
        return err

    err, locate_kie_api_out = raw_output_present(
        fact_names, host_vars,
        JBOSS_BRMS,
        'jboss_brms_locate_kie_api',
        "locate --basename 'kie-api*'")
    if err is not None:
        return err

    base_directories = set(business_central_candidates + kie_server_candidates)

    # manifest_mfs maps directory name to MANIFEST.MF contents
    manifest_mfs = {}
    for result in manifest_mf_out['results']:
        manifest_mfs[result['item']] = result['stdout']
    if sorted(list(manifest_mfs.keys())) != sorted(list(base_directories)):
        log.error('Bad manifest keys: %s, %s',
                  manifest_mfs.keys(), base_directories)

    # Dud entry here matches the UNKNOWN_BASE member of
    # kie_versions_by_directory, which is where we keep kie-api files
    # that aren't in a base directory we recognize.
    manifest_mfs[UNKNOWN_BASE] = ''

    kie_files = set(locate_kie_api_out['stdout_lines'])

    for result in kie_in_business_central_out['results']:
        if result['rc']:
            continue

        for filename in result['stdout_lines']:
            kie_files.add(filename)

    find_kie_api_out = host_vars.get('jboss.brms.kie-api-ver')
    if find_kie_api_out and 'stdout_lines' in find_kie_api_out:
        for filename in find_kie_api_out['stdout_lines']:
            kie_files.add(filename)

    # These loops could be implemented as a single pass through both
    # lists if we pre-sorted them. Waiting to see if anyone cares
    # about the performance of this code before optimizing.
    kie_versions_by_directory = {}
    for directory in base_directories:
        versions_in_dir = set()
        for filename in list(kie_files):
            if filename.startswith(directory):
                kie_files.remove(filename)
                category = classify_kie_file(filename)
                if category:
                    versions_in_dir.add(category)
                # Deliberately drop files if their category is falsey,
                # because it means that they are not Red Hat files.
        kie_versions_by_directory[directory] = versions_in_dir
    versions_in_dir = set()
    for filename in list(kie_files):
        category = classify_kie_file(filename)
        if category:
            versions_in_dir.add(category)
    kie_versions_by_directory[UNKNOWN_BASE] = versions_in_dir

    def format_directory_result(directory, manifest, kie_versions):
        """Format output for a single directory."""

        return (directory +
                ': ' +
                ('Red Hat manifest ' if 'Red Hat' in manifest else '') +
                'kie-api versions ' +
                '(' + encode_and_join('; ', kie_versions) + ')')  # noqa

    directories_for_output = [
        directory
        for directory in base_directories
        if ('Red Hat' in manifest_mfs[directory] or
            kie_versions_by_directory[directory])]
    if kie_versions_by_directory[UNKNOWN_BASE]:
        directories_for_output.append(UNKNOWN_BASE)

    found_redhat_brms = (
        any(('Red Hat' in manifest
             for _, manifest in utilities.iteritems(manifest_mfs))) or
        any((version
             for _, version
             in utilities.iteritems(kie_versions_by_directory))))

    jboss_vals = [format_directory_result(
        directory,
        manifest_mfs[directory],
        kie_versions_by_directory[directory])
                  for directory in directories_for_output]  # noqa E126
    jboss_vals += list(kie_files)
    return {JBOSS_BRMS:
            encode_and_join('; ', jboss_vals),
            JBOSS_BRMS_SUMMARY:
            ('Yes - BRMS installation present'
             if found_redhat_brms else 'No BRMS installation detected')}