Exemplo n.º 1
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template, rend, __opts__['renderer'], **kwargs)
    rmatcher = RosterMatcher(raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
Exemplo n.º 2
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    '''
    if tgt == 'all':
        tgt = '*'

    inventory_file = get_roster_file(__opts__)

    if os.path.isfile(inventory_file) and os.access(inventory_file, os.X_OK):
        imatcher = Script(tgt, tgt_type='glob', inventory_file=inventory_file)
    else:
        imatcher = Inventory(tgt, tgt_type='glob', inventory_file=inventory_file)
    return imatcher.targets()
Exemplo n.º 3
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    '''
    if tgt == 'all':
        tgt = '*'

    inventory_file = get_roster_file(__opts__)

    if os.path.isfile(inventory_file) and os.access(inventory_file, os.X_OK):
        imatcher = Script(tgt, tgt_type='glob', inventory_file=inventory_file)
    else:
        imatcher = Inventory(tgt, tgt_type='glob', inventory_file=inventory_file)
    return imatcher.targets()
Exemplo n.º 4
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template, rend, __opts__['renderer'],
                           __opts__['renderer_blacklist'],
                           __opts__['renderer_whitelist'], **kwargs)
    conditioned_raw = {}
    for minion in raw:
        conditioned_raw[str(minion)] = salt.config.apply_sdb(raw[minion])
    rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
Exemplo n.º 5
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    '''
    inventory = __runner__['salt.cmd'](
        'cmd.run',
        'ansible-inventory -i {0} --list'.format(get_roster_file(__opts__)))
    __context__['inventory'] = __utils__['json.loads'](
        __utils__['stringutils.to_str'](inventory))

    if tgt_type == 'glob':
        hosts = [
            host for host in _get_hosts_from_group('all')
            if fnmatch.fnmatch(host, tgt)
        ]
    elif tgt_type == 'nodegroup':
        hosts = _get_hosts_from_group(tgt)
    return {host: _get_hostvars(host) for host in hosts}
Exemplo n.º 6
0
def targets(tgt, tgt_type="glob", **kwargs):
    """
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    """
    inventory = __runner__["salt.cmd"]("cmd.run",
                                       "ansible-inventory -i {} --list".format(
                                           get_roster_file(__opts__)))
    __context__["inventory"] = __utils__["json.loads"](
        __utils__["stringutils.to_str"](inventory))

    if tgt_type == "glob":
        hosts = [
            host for host in _get_hosts_from_group("all")
            if fnmatch.fnmatch(host, tgt)
        ]
    elif tgt_type == "nodegroup":
        hosts = _get_hosts_from_group(tgt)
    return {host: _get_hostvars(host) for host in hosts}
Exemplo n.º 7
0
Arquivo: flat.py Projeto: bryson/salt
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template,
                           rend,
                           __opts__['renderer'],
                           __opts__['renderer_blacklist'],
                           __opts__['renderer_whitelist'],
                           **kwargs)
    conditioned_raw = {}
    for minion in raw:
        conditioned_raw[str(minion)] = raw[minion]
    rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
Exemplo n.º 8
0
def targets(tgt, tgt_type="glob", **kwargs):
    """
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    """
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template,
                           rend,
                           __opts__["renderer"],
                           __opts__["renderer_blacklist"],
                           __opts__["renderer_whitelist"],
                           mask_value="passw*",
                           **kwargs)
    conditioned_raw = {}
    for minion in raw:
        conditioned_raw[str(minion)] = salt.config.apply_sdb(raw[minion])
    return __utils__["roster_matcher.targets"](conditioned_raw, tgt, tgt_type,
                                               "ipv4")
Exemplo n.º 9
0
def targets(tgt, tgt_type="glob", **kwargs):
    """
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    """
    __context__["inventory"] = salt.utils.ansible.targets(
        inventory=get_roster_file(__opts__))

    if tgt_type == "glob":
        hosts = [
            host for host in _get_hosts_from_group("all")
            if fnmatch.fnmatch(host, tgt)
        ]
    elif tgt_type == "list":
        hosts = [host for host in _get_hosts_from_group("all") if host in tgt]
    elif tgt_type == "nodegroup":
        hosts = _get_hosts_from_group(tgt)
    else:
        hosts = []

    return {host: _get_hostvars(host) for host in hosts}
Exemplo n.º 10
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    '''
    inventory = __runner__['salt.cmd'](
        'cmd.run', 'ansible-inventory -i {0} --list'.format(get_roster_file(__opts__))
    )
    __context__['inventory'] = json.loads(utils_to_str(inventory))

    if tgt_type == 'nodegroup':
        hosts = _get_hosts_from_group(tgt)
        return {host: _get_hostvars(host) for host in hosts}
    pool = {host: _get_hostvars(host) for host in _get_hosts_from_group('all')}
    pool = salt_sproxy._roster.load_cache(
        pool, __runner__, __opts__, tgt, tgt_type=tgt_type
    )
    log.debug('Ansible devices pool')
    log.debug(pool)
    engine = salt_sproxy._roster.TGT_FUN[tgt_type]
    return engine(pool, tgt, opts=__opts__)
Exemplo n.º 11
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the sls file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)
    rend = salt.loader.render(__opts__, {})
    kwargs['__salt__'] = __runner__
    pool = compile_template(template,
                            rend,
                            __opts__['renderer'],
                            __opts__['renderer_blacklist'],
                            __opts__['renderer_whitelist'],
                            mask_value='passw*',
                            **kwargs)
    pool = {host: {'minion_opts': conf} for host, conf in pool.items()}
    pool = salt_sproxy._roster.load_cache(pool,
                                          __runner__,
                                          __opts__,
                                          tgt,
                                          tgt_type=tgt_type)
    engine = salt_sproxy._roster.TGT_FUN[tgt_type]
    return engine(pool, tgt, opts=__opts__)
Exemplo n.º 12
0
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    '''
    inventory = __runner__['salt.cmd'](
        'cmd.run',
        'ansible-inventory -i {0} --list'.format(get_roster_file(__opts__)))
    __context__['inventory'] = json.loads(utils_to_str(inventory))

    if tgt_type == 'glob':
        hosts = [
            host for host in _get_hosts_from_group('all')
            if fnmatch.fnmatch(host, tgt)
        ]
    elif tgt_type == 'list':
        hosts = [host for host in _get_hosts_from_group('all') if host in tgt]
    elif tgt_type == 'pcre':
        rgx = re.compile(tgt)
        hosts = [
            host for host in _get_hosts_from_group('all') if rgx.search(host)
        ]
    elif tgt_type in ['grain', 'grain_pcre']:
        grains = __runner__['cache.grains'](tgt, tgt_type=tgt_type)
        hosts = list(grains.keys())
    elif tgt_type in ['pillar', 'pillar_pcre']:
        pillars = __runner__['cache.pillar'](tgt, tgt_type=tgt_type)
        hosts = list(pillars.keys())
    # elif tgt_type == 'compound':
    # TODO: Implement the compound matcher, might need quite a bit of work,
    # need to evaluate if it's worth pulling all this code from
    # https://github.com/saltstack/salt/blob/develop/salt/matchers/compound_match.py
    # or find a smarter way to achieve that.
    elif tgt_type == 'nodegroup':
        hosts = _get_hosts_from_group(tgt)
    return {host: _get_hostvars(host) for host in hosts}