MCPcopy
hub / github.com/saltstack/salt / get

Function get

salt/modules/grains.py:86–125  ·  view source on GitHub ↗

Attempt to retrieve the named value from grains, if the named value is not available return the passed default. The default return is an empty string. The value can also represent a value in a nested dict using a ":" delimiter for the dict. This means that if a dict in grains looks

(key, default="", delimiter=DEFAULT_TARGET_DELIM, ordered=True)

Source from the content-addressed store, hash-verified

84
85
86def get(key, default="", delimiter=DEFAULT_TARGET_DELIM, ordered=True):
87 """
88 Attempt to retrieve the named value from grains, if the named value is not
89 available return the passed default. The default return is an empty string.
90
91 The value can also represent a value in a nested dict using a ":" delimiter
92 for the dict. This means that if a dict in grains looks like this::
93
94 {'pkg': {'apache': 'httpd'}}
95
96 To retrieve the value associated with the apache key in the pkg dict this
97 key can be passed::
98
99 pkg:apache
100
101
102 :param delimiter:
103 Specify an alternate delimiter to use when traversing a nested dict.
104 This is useful for when the desired key contains a colon. See CLI
105 example below for usage.
106
107 .. versionadded:: 2014.7.0
108
109 :param ordered:
110 Outputs an ordered dict if applicable (default: True)
111
112 .. versionadded:: 2016.11.0
113
114 CLI Example:
115
116 .. code-block:: bash
117
118 salt '*' grains.get pkg:apache
119 salt '*' grains.get abc::def|ghi delimiter='|'
120 """
121 if ordered is True:
122 grains = __grains__
123 else:
124 grains = salt.utils.json.loads(salt.utils.json.dumps(__grains__))
125 return salt.utils.data.traverse_dict_and_list(grains, key, default, delimiter)
126
127
128def has_value(key):

Callers 4

appendFunction · 0.70
removeFunction · 0.70
setFunction · 0.70
equalsFunction · 0.70

Calls 2

loadsMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected