salt.modules.environ

Support for getting and setting the environment variables of the current salt process.

salt.modules.environ.get(key, default='')

Get a single salt process environment variable.

key
String used as the key for environment lookup.
default
If the key is not found in the environment, return this value. Default: ''

CLI 范例:

salt '*' environ.get foo
salt '*' environ.get baz default=False
salt.modules.environ.has_value(key, value=None)

Determine whether the key exists in the current salt process environment dictionary. Optionally compare the current value of the environment against the supplied value string.

key
Must be a string. Used as key for environment lookup.
value:
Optional. If key exists in the environment, compare the current value with this value. Return True if they are equal.

CLI 范例:

salt '*' environ.has_value foo
salt.modules.environ.item(keys, default='')

Get one or more salt process environment variables. Returns a dict.

keys
Either a string or a list of strings that will be used as the keys for environment lookup.
default
If the key is not found in the environment, return this value. Default: ''

CLI 范例:

salt '*' environ.item foo
salt '*' environ.item '[foo, baz]' default=None
salt.modules.environ.items()

Return a dict of the entire environment set for the salt process

CLI 范例:

salt '*' environ.items
salt.modules.environ.setenv(environ, false_unsets=False, clear_all=False, update_minion=False, permanent=False)

Set multiple salt process environment variables from a dict. Returns a dict.

environ
Must be a dict. The top-level keys of the dict are the names of the environment variables to set. Each key's value must be a string or False. Refer to the 'false_unsets' parameter for behavior when a value set to False.
false_unsets
If a key's value is False and false_unsets is True, then the key will be removed from the salt processes environment dict entirely. If a key's value is False and false_unsets is not True, then the key's value will be set to an empty string. Default: False
clear_all
USE WITH CAUTION! This option can unset environment variables needed for salt to function properly. If clear_all is True, then any environment variables not defined in the environ dict will be deleted. Default: False
update_minion
If True, apply these environ changes to the main salt-minion process. If False, the environ changes will only affect the current salt subprocess. Default: False
permanent
On Windows minions this will set the environment variable in the registry so that it is always added as a environment variable when applications open. If you want to set the variable to HKLM instead of HKCU just pass in "HKLM" for this parameter. On all other minion types this will be ignored. Note: This will only take affect on applications opened after this has been set.

CLI 范例:

salt '*' environ.setenv '{"foo": "bar", "baz": "quux"}'
salt '*' environ.setenv '{"a": "b", "c": False}' false_unsets=True
salt.modules.environ.setval(key, val, false_unsets=False, permanent=False)

Set a single salt process environment variable. Returns True on success.

key
The environment key to set. Must be a string.
val
The value to set. Must be a string or False. Refer to the 'false_unsets' parameter for behavior when set to False.
false_unsets
If val is False and false_unsets is True, then the key will be removed from the salt processes environment dict entirely. If val is False and false_unsets is not True, then the key's value will be set to an empty string. Default: False.
permanent
On Windows minions this will set the environment variable in the registry so that it is always added as a environment variable when applications open. If you want to set the variable to HKLM instead of HKCU just pass in "HKLM" for this parameter. On all other minion types this will be ignored. Note: This will only take affect on applications opened after this has been set.

CLI 范例:

salt '*' environ.setval foo bar
salt '*' environ.setval baz val=False false_unsets=True
salt '*' environ.setval baz bar permanent=True
salt '*' environ.setval baz bar permanent=HKLM