salt.modules.saltutil

The Saltutil module is used to manage the state of the salt minion itself. It is used to manage minion modules as well as automate updates to the salt minion.

depends:
  • esky Python module for update functionality
salt.modules.saltutil.clear_cache()

Forcibly removes all caches on a minion.

2014.7.0 新版功能.

WARNING: The safest way to clear a minion cache is by first stopping the minion and then deleting the cache files before restarting it.

CLI 范例:

salt '*' saltutil.clear_cache
salt.modules.saltutil.cmd(tgt, fun, arg=(), timeout=None, expr_form='glob', ret='', kwarg=None, ssh=False, **kwargs)

Assuming this minion is a master, execute a salt command

CLI 范例:

salt '*' saltutil.cmd
salt.modules.saltutil.cmd_iter(tgt, fun, arg=(), timeout=None, expr_form='glob', ret='', kwarg=None, ssh=False, **kwargs)

Assuming this minion is a master, execute a salt command

CLI 范例:

salt '*' saltutil.cmd_iter
salt.modules.saltutil.find_cached_job(jid)

Return the data for a specific cached job id. Note this only works if cache_jobs has previously been set to True on the minion.

CLI 范例:

salt '*' saltutil.find_cached_job <job id>
salt.modules.saltutil.find_job(jid)

Return the data for a specific job id

CLI 范例:

salt '*' saltutil.find_job <job id>
salt.modules.saltutil.is_running(fun)

If the named function is running return the data associated with it/them. The argument can be a glob

CLI 范例:

salt '*' saltutil.is_running state.highstate
salt.modules.saltutil.kill_job(jid)

Sends a kill signal (SIGKILL 9) to the named salt job's process

CLI 范例:

salt '*' saltutil.kill_job <job id>
salt.modules.saltutil.mmodule(saltenv, fun, *args, **kwargs)

Loads minion modules from an environment so that they can be used in pillars for that environment

CLI 范例:

salt '*' saltutil.mmodule base test.ping
salt.modules.saltutil.refresh_beacons()

Signal the minion to refresh the beacons.

CLI 范例:

salt '*' saltutil.refresh_beacons
salt.modules.saltutil.refresh_modules(async=True)

Signal the minion to refresh the module and grain data

The default is to refresh module asynchronously. To block until the module refresh is complete, set the 'async' flag to False.

CLI 范例:

salt '*' saltutil.refresh_modules
salt.modules.saltutil.refresh_pillar()

Signal the minion to refresh the pillar data.

CLI 范例:

salt '*' saltutil.refresh_pillar
salt.modules.saltutil.regen_keys()

Used to regenerate the minion keys.

CLI 范例:

salt '*' saltutil.regen_keys
salt.modules.saltutil.revoke_auth(preserve_minion_cache=False)

The minion sends a request to the master to revoke its own key. Note that the minion session will be revoked and the minion may not be able to return the result of this command back to the master.

If the 'preserve_minion_cache' flag is set to True, the master cache for this minion will not be removed.

CLI 范例:

salt '*' saltutil.revoke_auth
salt.modules.saltutil.runner(_fun, **kwargs)

Execute a runner module (this function must be run on the master)

2014.7.0 新版功能.

name
The name of the function to run
kwargs
Any keyword arguments to pass to the runner function

CLI 范例:

salt '*' saltutil.runner jobs.list_jobs
salt.modules.saltutil.running()

Return the data on all running salt processes on the minion

CLI 范例:

salt '*' saltutil.running
salt.modules.saltutil.signal_job(jid, sig)

Sends a signal to the named salt job's process

CLI 范例:

salt '*' saltutil.signal_job <job id> 15
salt.modules.saltutil.sync_all(saltenv=None, refresh=True)

Sync down all of the dynamic modules from the file server for a specific environment. This function synchronizes custom modules, states, beacons, grains, returners, output modules, renderers, and utils.

refresh : True
Also refresh the execution modules and recompile pillar data available to the minion. This refresh will be performed even if no new dynamic modules are synced. Set to False to prevent this refresh.

重要

If this function is executed using a module.run state, the SLS file will not have access to newly synced execution modules unless a refresh argument is added to the state, like so:

load_my_custom_module:
  module.run:
    - name: saltutil.sync_all
    - refresh: True

See here for a more detailed explanation of why this is necessary.

CLI Examples:

salt '*' saltutil.sync_all
salt '*' saltutil.sync_all saltenv=base,dev
salt.modules.saltutil.sync_beacons(saltenv=None, refresh=True)

2015.5.1 新版功能.

Sync beacons from salt://_beacons to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available beacons on the minion. This refresh will be performed even if no new beacons are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_beacons
salt '*' saltutil.sync_beacons saltenv=base,dev
salt.modules.saltutil.sync_grains(saltenv=None, refresh=True)

0.10.0 新版功能.

Sync grains modules from salt://_grains to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules and recompile pillar data for the minion. This refresh will be performed even if no new grains modules are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_grains
salt '*' saltutil.sync_grains saltenv=base,dev
salt.modules.saltutil.sync_log_handlers(saltenv=None, refresh=True)

2015.8.0 新版功能.

Sync log handlers from salt://_log_handlers to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new log handlers are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_log_handlers
salt '*' saltutil.sync_log_handlers saltenv=base,dev
salt.modules.saltutil.sync_modules(saltenv=None, refresh=True)

0.10.0 新版功能.

Sync execution modules from salt://_modules to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new execution modules are synced. Set to False to prevent this refresh.

重要

If this function is executed using a module.run state, the SLS file will not have access to newly synced execution modules unless a refresh argument is added to the state, like so:

load_my_custom_module:
  module.run:
    - name: saltutil.sync_modules
    - refresh: True

See here for a more detailed explanation of why this is necessary.

CLI Examples:

salt '*' saltutil.sync_modules
salt '*' saltutil.sync_modules saltenv=base,dev
salt.modules.saltutil.sync_output(saltenv=None, refresh=True)

Sync outputters from salt://_output to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new outputters are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_output
salt '*' saltutil.sync_output saltenv=base,dev
salt.modules.saltutil.sync_outputters(saltenv=None, refresh=True)

This function is an alias of sync_output.

Sync outputters from salt://_output to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new outputters are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_output
salt '*' saltutil.sync_output saltenv=base,dev
salt.modules.saltutil.sync_proxymodules(saltenv=None, refresh=False)

2015.8.2 新版功能.

Sync proxy modules from salt://_proxy to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new proxy modules are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_proxymodules
salt '*' saltutil.sync_proxymodules saltenv=base,dev
salt.modules.saltutil.sync_renderers(saltenv=None, refresh=True)

0.10.0 新版功能.

Sync renderers from salt://_renderers to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new renderers are synced. Set to False to prevent this refresh. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_renderers
salt '*' saltutil.sync_renderers saltenv=base,dev
salt.modules.saltutil.sync_returners(saltenv=None, refresh=True)

0.10.0 新版功能.

Sync beacons from salt://_returners to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new returners are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_returners
salt.modules.saltutil.sync_sdb(saltenv=None)

2015.5.8,2015.8.3 新版功能.

Sync sdb modules from salt://_sdb to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.

CLI Examples:

salt '*' saltutil.sync_sdb
salt '*' saltutil.sync_sdb saltenv=base,dev
salt.modules.saltutil.sync_states(saltenv=None, refresh=True)

0.10.0 新版功能.

Sync state modules from salt://_states to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available states on the minion. This refresh will be performed even if no new state modules are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_states
salt '*' saltutil.sync_states saltenv=base,dev
salt.modules.saltutil.sync_utils(saltenv=None, refresh=True)

2014.7.0 新版功能.

Sync utility modules from salt://_utils to the minion

saltenv : base
The fileserver environment from which to sync. To sync from more than one environment, pass a comma-separated list.
refresh : True
If True, refresh the available execution modules on the minion. This refresh will be performed even if no new utility modules are synced. Set to False to prevent this refresh.

CLI Examples:

salt '*' saltutil.sync_utils
salt '*' saltutil.sync_utils saltenv=base,dev
salt.modules.saltutil.term_job(jid)

Sends a termination signal (SIGTERM 15) to the named salt job's process

CLI 范例:

salt '*' saltutil.term_job <job id>
salt.modules.saltutil.update(version=None)

Update the salt minion from the URL defined in opts['update_url'] SaltStack, Inc provides the latest builds here: update_url: https://repo.saltstack.com/windows/

Be aware that as of 2014-8-11 there's a bug in esky such that only the latest version available in the update_url can be downloaded and installed.

This feature requires the minion to be running a bdist_esky build.

The version number is optional and will default to the most recent version available at opts['update_url'].

Returns details about the transaction upon completion.

CLI Examples:

salt '*' saltutil.update
salt '*' saltutil.update 0.10.3
salt.modules.saltutil.wheel(_fun, **kwargs)

Execute a wheel module (this function must be run on the master)

2014.7.0 新版功能.

name
The name of the function to run
kwargs
Any keyword arguments to pass to the wheel function

CLI 范例:

salt '*' saltutil.wheel key.accept match=jerry