You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
2014.1.0 regression: match.glob in pillar returns value for master #11517
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
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:
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.
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
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.
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:
@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.
@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.
Activity
[-]2014.1 regression: match.glob in pillar returns value for master[/-][+]2014.1.0 regression: match.glob in pillar returns value for master[/+]basepi commentedon Mar 25, 2014
Very strange. Thanks for the report, we'll investigate.
steverweber commentedon Mar 26, 2014
I also hit this one today in a pillar. /confirmed/
the match only matches on one host..
terminalmage commentedon Apr 12, 2014
@steverweber Are you saying that both of those functions are failing to work as expected? Or just match.glob?
terminalmage commentedon Apr 12, 2014
I'm suspicious that this ever would have worked in a pillar SLS file, since pillar data is compiled on the master.
steverweber commentedon Apr 12, 2014
Humm. Ic perhaps this is a feature request. This functionality will be import to us. I'll take a look into this tomorrow.
terminalmage commentedon Apr 13, 2014
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:
If you place that into a file called foo.py, and place that file within a directory called
_grainsin the root of your salt fileserver (so,/srv/salt/_grains/foo.pyif using the default file_roots configuration), then you can sync the custom grain module to your minions usingsalt '*' saltutil.sync_grains, and the data would be available in grains rather than pillar.steverweber commentedon Apr 13, 2014
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:
perhaps something like:
salt/salt/modules/match.py
with an added argument of opts would work.
then in a pillar we could do
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.terminalmage commentedon Apr 13, 2014
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) %}terminalmage commentedon Apr 13, 2014
Keep in mind that you can also use matching in the pillar top.sls to assign your SLS data. For example:
Then you can have a foopillar.sls and barpillar.sls containing the pillar data you wanted to set.
terminalmage commentedon Apr 13, 2014
@steverweber I have a fix ready for this, I'm going out for lunch right now though. Will submit this later on.
terminalmage commentedon Apr 13, 2014
Well, not so much a "fix", as a feature add.
terminalmage commentedon Apr 13, 2014
@steverweber I've just submitted a pull request (#11965) which allows the minion ID to be overridden for
match.list,match.glob,match.compound, andmatch.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.
steverweber commentedon Apr 13, 2014
Thanks!
terminalmage commentedon Apr 14, 2014
No prob! You can use
grains['id']to get the minion ID for the override. I neglected to mention that.steverweber commentedon Apr 14, 2014
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 :)
terminalmage commentedon Apr 14, 2014
@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.
steverweber commentedon Apr 14, 2014
Perfect. Nice job!.
terminalmage commentedon Apr 14, 2014
Since my pull request fixes this, I am going to close this one.