fix grains filter_by function when using salt-ssh

This is very similar to #18238 and 7975b0a11.

For a more verbose description see #18238.