Skip to content

2014.1.0 regression: match.glob in pillar returns value for master #11517

Closed

Description

@Mrten

0.17.5 did not do that.

I use in a !py renderer:

 if __salt__['match.glob']('web-*'):
          render = True

the __salt['match.glob']() call returns False all the time now. If I replace 'web-*' with the name of the master it returns True.

Activity

  1. changed the title [-]2014.1 regression: match.glob in pillar returns value for master[/-] [+]2014.1.0 regression: match.glob in pillar returns value for master[/+] on Mar 25, 2014
  2. basepi commented on Mar 25, 2014

    @basepi
    Contributor

    Very strange. Thanks for the report, we'll investigate.

  3. added this to the Outstanding Bugs milestone on Mar 25, 2014
  4. steverweber commented on Mar 26, 2014

    @steverweber
    Contributor

    I also hit this one today in a pillar. /confirmed/

    is_pcre: {{ salt['match.pcre']('cent0.*') }}
    is_glob: {{ salt['match.glob']('localhost') }}
    

    the match only matches on one host..

  5. terminalmage commented on Apr 12, 2014

    @terminalmage
    Contributor

    @steverweber Are you saying that both of those functions are failing to work as expected? Or just match.glob?

  6. terminalmage commented on Apr 12, 2014

    @terminalmage
    Contributor

    I'm suspicious that this ever would have worked in a pillar SLS file, since pillar data is compiled on the master.

  7. steverweber commented on Apr 12, 2014

    @steverweber
    Contributor

    Humm. Ic perhaps this is a feature request. This functionality will be import to us. I'll take a look into this tomorrow.

  8. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    It is very unlikely that changes will be made to how the pillar data is compiled, there are very good reasons for it to be compiled on the master. You might be better off writing a custom grains module, like so:

    def run():
        return {
            'is_pcre': __salt__['match.pcre']('cent0.*'),
            'is_glob': __salt__['match.glob']('localhost')
        }

    If you place that into a file called foo.py, and place that file within a directory called _grains in the root of your salt fileserver (so, /srv/salt/_grains/foo.py if using the default file_roots configuration), then you can sync the custom grain module to your minions using salt '*' saltutil.sync_grains, and the data would be available in grains rather than pillar.

  9. steverweber commented on Apr 13, 2014

    @steverweber
    Contributor

    We are staying away from grains because of possible security issues.

    Our environment is rather large and eventually may need 'sub' top pillar files.

    My current solution is a pillar file like:

    {%
    set _roles_of_idregex = {
      'localhost': ['mfcf.master'],
      'dhcp': ['mfcf.pkg'],
    }
    %}
    
    my_id: {{ opts['id'] }}
    TEST_FAILED_is_pcre: {{ salt['match.pcre']('cent0.*') }}
    TEST_FAILED_is_glob: {{ salt['match.glob']('localhost') }}
    
    {% for idregex in _roles_of_idregex %}
      {% if opts['id'] in idregex %}
            # TODO: would be nice to use something like... if salt['match.pcre'](idregex)
    include:
        {% for role in _roles_of_idregex[idregex] %}
      - {{ role }}
        {% endfor %}
      {% endif %}
    {% endfor %}
    

    perhaps something like:
    salt/salt/modules/match.py
    with an added argument of opts would work.

    def pcre(tgt, opts=None):
        '''
        Return True if the minion matches the given pcre target
    
        CLI Example:
    
        .. code-block:: bash
    
            salt '*' match.pcre '.*'
        '''
        if not opts:
          opts = __opts__
        matcher = salt.minion.Matcher(opts, __salt__)
        try:
            return matcher.pcre_match(tgt)
        except Exception as exc:
            log.exception(exc)
            return False
    
    
    def glob(tgt, opts=None):
        '''
        Return True if the minion matches the given glob target
    
        CLI Example:
    
        .. code-block:: bash
    
            salt '*' match.glob '*'
        '''
       if not opts:
          opts = __opts__
        matcher = salt.minion.Matcher(opts, __salt__)
        try:
            return matcher.glob_match(tgt)
        except Exception as exc:
            log.exception(exc)
            return False
    

    then in a pillar we could do

    is_pcre_cent0: {{ salt['match.pcre']('cent0.*', opts) }}
    is_glob_localhost: {{ salt['match.glob']('localhost', opts) }}
    

    I dont really like this idea of adding a extra opts argument because I kinda feel like the match module should already have the correct __opts__['id'] that is what the pillar is rendering... I admit I dont know much of the inner workings of salt. My feeling could vary well be wrong and break things.

  10. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    Well, Pillar is designed to be able to be used as a way to provide sensitive data (such as password hashes, private keys, etc) for SLS files. As such, it is compiled on the master, and any functions (like match.glob) will be run on the master, not the minions.

    Adding an argument to the match.* functions might be a step in the direction of what you want, but to be able to fully support matching a minion within a pillar SLS file, I'd need to look for ways of accessing the current host which is having its pillar data evaluated. Then it would be possible to do something like:

    {% salt['match.glob']('foo*', minion_id=current_minion_id) %}
  11. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    Keep in mind that you can also use matching in the pillar top.sls to assign your SLS data. For example:

    base:
      'foo*':
        - foopillar
      'bar[0-9]+\.internaldomain':
        - match: pcre
        - barpillar

    Then you can have a foopillar.sls and barpillar.sls containing the pillar data you wanted to set.

  12. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    @steverweber I have a fix ready for this, I'm going out for lunch right now though. Will submit this later on.

  13. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    Well, not so much a "fix", as a feature add.

  14. terminalmage commented on Apr 13, 2014

    @terminalmage
    Contributor

    @steverweber I've just submitted a pull request (#11965) which allows the minion ID to be overridden for match.list, match.glob, match.compound, and match.pcre, the four functions which match the minion ID. This feature should make it into the next feature release, at the latest.

    In the meantime, this patch will work against 2014.1.0 and 2014.1.1, and will provide the new functionality.

  15. steverweber commented on Apr 13, 2014

    @steverweber
    Contributor

    Thanks!

  16. terminalmage commented on Apr 14, 2014

    @terminalmage
    Contributor

    No prob! You can use grains['id'] to get the minion ID for the override. I neglected to mention that.

  17. steverweber commented on Apr 14, 2014

    @steverweber
    Contributor

    I have been using opts['id'] instead of grains. I guess thats what caused me to question the behaviour of match.*

    Im glad this patch got pulled in. Now I have a neat hack that will allow me to use regex in pillars :)

  18. terminalmage commented on Apr 14, 2014

    @terminalmage
    Contributor

    @steverweber I actually improved upon the fix, and it no longer requires the minion ID to be overridden in pillar SLS files. It seemed a bit annoying to force people to do that just for their pillar SLS files, so I found a better way. The patch I posted has been updated, as has the pull request.

  19. steverweber commented on Apr 14, 2014

    @steverweber
    Contributor

    Perfect. Nice job!.

  20. terminalmage commented on Apr 14, 2014

    @terminalmage
    Contributor

    Since my pull request fixes this, I am going to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugexpected-behaviorseverity-low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions