diff --git a/changelog/56093.fixed b/changelog/56093.fixed new file mode 100644 index 00000000000..2b898dd72f3 --- /dev/null +++ b/changelog/56093.fixed @@ -0,0 +1 @@ +Fixed pillar.filter_by with salt-ssh diff --git a/salt/client/ssh/wrapper/pillar.py b/salt/client/ssh/wrapper/pillar.py index 00a799de543..98fcb66a9ff 100644 --- a/salt/client/ssh/wrapper/pillar.py +++ b/salt/client/ssh/wrapper/pillar.py @@ -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