Fix pillar.filter_by with salt-ssh

This commit is contained in:
jeanluc 2022-11-08 15:40:00 +01:00 committed by Megan Wilhite
parent af1b2ff2ef
commit 7cff6d3dff
2 changed files with 59 additions and 0 deletions

1
changelog/56093.fixed Normal file
View file

@ -0,0 +1 @@
Fixed pillar.filter_by with salt-ssh

View file

@ -141,6 +141,64 @@ def keys(key, delimiter=DEFAULT_TARGET_DELIM):
return ret.keys()
def filter_by(lookup_dict, pillar, merge=None, default="default", base=None):
"""
.. versionadded:: 2017.7.0
Look up the given pillar in a given dictionary and return the result
:param lookup_dict: A dictionary, keyed by a pillar, containing a value or
values relevant to systems matching that pillar. For example, a key
could be a pillar for a role and the value could the name of a package
on that particular OS.
The dictionary key can be a globbing pattern. The function will return
the corresponding ``lookup_dict`` value where the pillar value matches
the pattern. For example:
.. code-block:: bash
# this will render 'got some salt' if ``role`` begins with 'salt'
salt '*' pillar.filter_by '{salt*: got some salt, default: salt is not here}' role
:param pillar: The name of a pillar to match with the system's pillar. For
example, the value of the "role" pillar could be used to pull values
from the ``lookup_dict`` dictionary.
The pillar value can be a list. The function will return the
``lookup_dict`` value for a first found item in the list matching
one of the ``lookup_dict`` keys.
:param merge: A dictionary to merge with the results of the pillar
selection from ``lookup_dict``. This allows another dictionary to
override the values in the ``lookup_dict``.
:param default: default lookup_dict's key used if the pillar does not exist
or if the pillar value has no match on lookup_dict. If unspecified
the value is "default".
:param base: A lookup_dict key to use for a base dictionary. The
pillar-selected ``lookup_dict`` is merged over this and then finally
the ``merge`` dictionary is merged. This allows common values for
each case to be collected in the base and overridden by the pillar
selection dictionary and the merge dictionary. Default is unset.
CLI Example:
.. code-block:: bash
salt '*' pillar.filter_by '{web: Serve it up, db: I query, default: x_x}' role
"""
return salt.utils.data.filter_by(
lookup_dict=lookup_dict,
lookup=pillar,
traverse=__pillar__.value(),
merge=merge,
default=default,
base=base,
)
# Allow pillar.data to also be used to return pillar data
items = raw
data = items