mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix grains.has_value when value is False
This function returns a boolean based on the boolean result of the value returned when looking up the key. However, this means that if a key exists and has a value of 0, an empty string, or False/None, grains.has_value will incorrectly return False. This fixes that by only returning False when the key is not present.
This commit is contained in:
parent
9ac3f2ea7b
commit
bf45ae6e6a
1 changed files with 5 additions and 2 deletions
|
@ -121,7 +121,7 @@ def get(key, default='', delimiter=DEFAULT_TARGET_DELIM, ordered=True):
|
|||
|
||||
def has_value(key):
|
||||
'''
|
||||
Determine whether a named value exists in the grains dictionary.
|
||||
Determine whether a key exists in the grains dictionary.
|
||||
|
||||
Given a grains dictionary that contains the following structure::
|
||||
|
||||
|
@ -137,7 +137,10 @@ def has_value(key):
|
|||
|
||||
salt '*' grains.has_value pkg:apache
|
||||
'''
|
||||
return True if salt.utils.traverse_dict_and_list(__grains__, key, False) else False
|
||||
return salt.utils.traverse_dict_and_list(
|
||||
__grains__,
|
||||
key,
|
||||
KeyError) is not KeyError
|
||||
|
||||
|
||||
def items(sanitize=False):
|
||||
|
|
Loading…
Add table
Reference in a new issue