Example #1
0
def get_hosts_files(option):
    """
    Find out the location of the `hosts` file. This looks in multiple places
    such as the `-i` option, current dir and ansible configuration files. The
    first match is returned as a list.
    """
    if option is not None:
        return option.split(',')

    # Use hosts file from the current dir if it exists
    if os.path.isfile('hosts'):
        return ['hosts']

    # Perhaps it's configured in a configuration file. Try to find a
    # configuration file and see if it contains a `hostsfile` entry.
    config_locations = [
        '.',
        '/etc/ansible/'
    ]
    config_dir = util.find_path(config_locations, 'ansible.cfg')
    log.debug('config_dir = {0}'.format(config_dir))
    if config_dir:
        with open(os.path.join(config_dir, 'ansible.cfg'), 'r') as cf:
            for line in cf:
                if line.startswith('hostfile'):
                    return [line.split('=', 1)[1].strip()]
Example #2
0
def get_hosts_files(option):
    """
    Find out the location of the `hosts` file. This looks in multiple places
    such as the `-i` option, current dir and ansible configuration files. The
    first match is returned as a list.
    """
    if option is not None:
        return option.split(',')

    # Use hosts file from the current dir if it exists
    if os.path.isfile('hosts'):
        return ['hosts']

    # Perhaps it's configured in a configuration file. Try to find a
    # configuration file and see if it contains a `hostsfile` entry.
    config_locations = [
        '.',
        '/etc/ansible/'
    ]
    config_dir = util.find_path(config_locations, 'ansible.cfg')
    log.debug('config_dir = {0}'.format(config_dir))
    if config_dir:
        with open(os.path.join(config_dir, 'ansible.cfg'), 'r') as cf:
            for line in cf:
                if line.startswith('hostfile'):
                    return [line.split('=', 1)[1].strip()]
Example #3
0
def get_data_dir():
    """
    Find out our installation prefix and data directory. These can be in
    different places depending on how ansible-cmdb was installed.
    """
    data_dir_paths = [
        os.path.join(os.path.dirname(ansiblecmdb.__file__), 'data'),
        os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib', 'ansiblecmdb', 'data'),
        '/usr/local/lib/ansiblecmdb/data',
        '/usr/lib/ansiblecmdb/data',
    ]

    data_dir = util.find_path(data_dir_paths, 'tpl/html_fancy.tpl')
    if not data_dir:
        sys.stdout.write("Couldn't find the data dir for the templates. I tried: {0}\n".format(", ".join(data_dir_paths)))
        sys.exit(1)

    return data_dir
Example #4
0
def get_data_dir():
    """
    Find out our installation prefix and data directory. These can be in
    different places depending on how ansible-cmdb was installed.
    """
    data_dir_paths = [
        os.path.join(os.path.dirname(ansiblecmdb.__file__), 'data'),
        os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib', 'ansiblecmdb', 'data'),
        '/usr/local/lib/ansiblecmdb/data',
        '/usr/lib/ansiblecmdb/data',
    ]

    data_dir = util.find_path(data_dir_paths, 'tpl/html_fancy.tpl')
    if not data_dir:
        sys.stdout.write("Couldn't find the data dir for the templates. I tried: {0}\n".format(", ".join(data_dir_paths)))
        sys.exit(1)

    return data_dir